Debian Codegraph @

upstream/debian-unstable/man3/sem_getvalue.3

raw
1 '\" t
2 .\" Copyright 2006, Michael Kerrisk <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH sem_getvalue 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 sem_getvalue \- get the value of a semaphore
10 .SH LIBRARY
11 POSIX threads library
12 .RI ( libpthread ,\~ \-lpthread )
13 .SH SYNOPSIS
14 .nf
15 .B #include <semaphore.h>
16 .P
17 .BI "int sem_getvalue(sem_t *restrict " sem ", int *restrict " sval );
18 .fi
19 .SH DESCRIPTION
20 .BR sem_getvalue ()
21 places the current value of the semaphore pointed to
22 .I sem
23 into the integer pointed to by
24 .IR sval .
25 .P
26 If one or more processes or threads are blocked
27 waiting to lock the semaphore with
28 .BR sem_wait (3),
29 POSIX.1 permits two possibilities for the value returned in
30 .IR sval :
31 either 0 is returned;
32 or a negative number whose absolute value is the count
33 of the number of processes and threads currently blocked in
34 .BR sem_wait (3).
35 Linux adopts the former behavior.
36 .SH RETURN VALUE
37 .BR sem_getvalue ()
38 returns 0 on success;
39 on error, \-1 is returned and
40 .I errno
41 is set to indicate the error.
42 .SH ERRORS
43 .TP
44 .B EINVAL
45 .I sem
46 is not a valid semaphore.
47 (The glibc implementation currently does not check whether
48 .I sem
49 is valid.)
50 .SH ATTRIBUTES
51 For an explanation of the terms used in this section, see
52 .BR attributes (7).
53 .TS
54 allbox;
55 lbx lb lb
56 l l l.
57 Interface Attribute Value
58 T{
59 .na
60 .nh
61 .BR sem_getvalue ()
62 T} Thread safety MT-Safe
63 .TE
64 .SH STANDARDS
65 POSIX.1-2008.
66 .SH HISTORY
67 POSIX.1-2001.
68 .SH NOTES
69 The value of the semaphore may already have changed by the time
70 .BR sem_getvalue ()
71 returns.
72 .SH SEE ALSO
73 .BR sem_post (3),
74 .BR sem_wait (3),
75 .BR sem_overview (7)