]>
Commit | Line | Data |
---|---|---|
c11b1abf | 1 | .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com> |
2c731798 | 2 | .\" |
5fbde956 | 3 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
2c731798 | 4 | .\" |
45186a5d | 5 | .TH SEM_GETVALUE 3 2021-03-22 "Linux man-pages (unreleased)" |
2c731798 MK |
6 | .SH NAME |
7 | sem_getvalue \- get the value of a semaphore | |
911c89d5 AC |
8 | .SH LIBRARY |
9 | POSIX threads library | |
8fc3b2cf | 10 | .RI ( libpthread ", " \-lpthread ) |
2c731798 MK |
11 | .SH SYNOPSIS |
12 | .nf | |
13 | .B #include <semaphore.h> | |
68e4db0a | 14 | .PP |
439cb1d4 | 15 | .BI "int sem_getvalue(sem_t *restrict " sem ", int *restrict " sval ); |
2c731798 MK |
16 | .fi |
17 | .SH DESCRIPTION | |
18 | .BR sem_getvalue () | |
19 | places the current value of the semaphore pointed to | |
20 | .I sem | |
21 | into the integer pointed to by | |
22 | .IR sval . | |
847e0d88 | 23 | .PP |
c13182ef | 24 | If one or more processes or threads are blocked |
2c731798 MK |
25 | waiting to lock the semaphore with |
26 | .BR sem_wait (3), | |
4b6fa602 | 27 | POSIX.1 permits two possibilities for the value returned in |
4509e795 | 28 | .IR sval : |
c13182ef MK |
29 | either 0 is returned; |
30 | or a negative number whose absolute value is the count | |
2c731798 MK |
31 | of the number of processes and threads currently blocked in |
32 | .BR sem_wait (3). | |
d9bfdb9c | 33 | Linux adopts the former behavior. |
2c731798 MK |
34 | .SH RETURN VALUE |
35 | .BR sem_getvalue () | |
c13182ef | 36 | returns 0 on success; |
2c731798 | 37 | on error, \-1 is returned and |
c13182ef | 38 | .I errno |
2c731798 MK |
39 | is set to indicate the error. |
40 | .SH ERRORS | |
41 | .TP | |
42 | .B EINVAL | |
43 | .I sem | |
44 | is not a valid semaphore. | |
777ab17e MK |
45 | (The glibc implementation currently does not check whether |
46 | .I sem | |
47 | is valid.) | |
044738b4 | 48 | .SH ATTRIBUTES |
3533c7f0 PH |
49 | For an explanation of the terms used in this section, see |
50 | .BR attributes (7). | |
c466875e MK |
51 | .ad l |
52 | .nh | |
3533c7f0 PH |
53 | .TS |
54 | allbox; | |
c466875e | 55 | lbx lb lb |
3533c7f0 PH |
56 | l l l. |
57 | Interface Attribute Value | |
58 | T{ | |
044738b4 | 59 | .BR sem_getvalue () |
3533c7f0 PH |
60 | T} Thread safety MT-Safe |
61 | .TE | |
c466875e MK |
62 | .hy |
63 | .ad | |
64 | .sp 1 | |
3113c7f3 | 65 | .SH STANDARDS |
4b6fa602 | 66 | POSIX.1-2001, POSIX.1-2008. |
2c731798 MK |
67 | .SH NOTES |
68 | The value of the semaphore may already have changed by the time | |
69 | .BR sem_getvalue () | |
70 | returns. | |
47297adb | 71 | .SH SEE ALSO |
2c731798 MK |
72 | .BR sem_post (3), |
73 | .BR sem_wait (3), | |
74 | .BR sem_overview (7) |