1sem_getvalue(3)            Library Functions Manual            sem_getvalue(3)
2
3
4

NAME

6       sem_getvalue - get the value of a semaphore
7

LIBRARY

9       POSIX threads library (libpthread, -lpthread)
10

SYNOPSIS

12       #include <semaphore.h>
13
14       int sem_getvalue(sem_t *restrict sem, int *restrict sval);
15

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

ATTRIBUTES

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

STANDARDS

46       POSIX.1-2008.
47

HISTORY

49       POSIX.1-2001.
50

NOTES

52       The value of the  semaphore  may  already  have  changed  by  the  time
53       sem_getvalue() returns.
54

SEE ALSO

56       sem_post(3), sem_wait(3), sem_overview(7)
57
58
59
60Linux man-pages 6.04              2023-03-30                   sem_getvalue(3)
Impressum