1SEM_GETVALUE(3)            Linux Programmer's Manual           SEM_GETVALUE(3)
2
3
4

NAME

6       sem_getvalue - get the value of a semaphore
7

SYNOPSIS

9       #include <semaphore.h>
10
11       int sem_getvalue(sem_t *restrict sem, int *restrict sval);
12
13       Link with -pthread.
14

DESCRIPTION

16       sem_getvalue() places the current value of the semaphore pointed to sem
17       into the integer pointed to by sval.
18
19       If one or more processes or threads are blocked  waiting  to  lock  the
20       semaphore  with  sem_wait(3), POSIX.1 permits two possibilities for the
21       value returned in sval: either 0 is  returned;  or  a  negative  number
22       whose  absolute  value  is  the  count  of  the number of processes and
23       threads currently blocked in sem_wait(3).  Linux adopts the former  be‐
24       havior.
25

RETURN VALUE

27       sem_getvalue() returns 0 on success; on error, -1 is returned and errno
28       is set to indicate the error.
29

ERRORS

31       EINVAL sem is not a valid semaphore.  (The  glibc  implementation  cur‐
32              rently does not check whether sem is valid.)
33

ATTRIBUTES

35       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
36       tributes(7).
37
38       ┌────────────────────────────────────────────┬───────────────┬─────────┐
39Interface                                   Attribute     Value   
40       ├────────────────────────────────────────────┼───────────────┼─────────┤
41sem_getvalue()                              │ Thread safety │ MT-Safe │
42       └────────────────────────────────────────────┴───────────────┴─────────┘
43

CONFORMING TO

45       POSIX.1-2001, POSIX.1-2008.
46

NOTES

48       The value of the  semaphore  may  already  have  changed  by  the  time
49       sem_getvalue() returns.
50

SEE ALSO

52       sem_post(3), sem_wait(3), sem_overview(7)
53

COLOPHON

55       This  page  is  part of release 5.12 of the Linux man-pages project.  A
56       description of the project, information about reporting bugs,  and  the
57       latest     version     of     this    page,    can    be    found    at
58       https://www.kernel.org/doc/man-pages/.
59
60
61
62Linux                             2021-03-22                   SEM_GETVALUE(3)
Impressum