OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / sem_getvalue.3
1 '\" t
2 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .TH SEM_GETVALUE 3 2014-03-03 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 sem_getvalue \- get the value of a semaphore
29 .SH SYNOPSIS
30 .nf
31 .B #include <semaphore.h>
32 .sp
33 .BI "int sem_getvalue(sem_t *" sem ", int *" sval );
34 .fi
35 .sp
36 Link with \fI\-pthread\fP.
37 .SH DESCRIPTION
38 .BR sem_getvalue ()
39 places the current value of the semaphore pointed to
40 .I sem
41 into the integer pointed to by
42 .IR sval .
43
44 If one or more processes or threads are blocked
45 waiting to lock the semaphore with
46 .BR sem_wait (3),
47 POSIX.1-2001 permits two possibilities for the value returned in
48 .IR sval :
49 either 0 is returned;
50 or a negative number whose absolute value is the count
51 of the number of processes and threads currently blocked in
52 .BR sem_wait (3).
53 Linux adopts the former behavior.
54 .SH RETURN VALUE
55 .BR sem_getvalue ()
56 returns 0 on success;
57 on error, \-1 is returned and
58 .I errno
59 is set to indicate the error.
60 .SH ERRORS
61 .TP
62 .B EINVAL
63 .I sem
64 is not a valid semaphore.
65 .SH ATTRIBUTES
66 .SS Multithreading (see pthreads(7))
67 The
68 .BR sem_getvalue ()
69 function is thread-safe.
70 .SH CONFORMING TO
71 POSIX.1-2001.
72 .SH NOTES
73 The value of the semaphore may already have changed by the time
74 .BR sem_getvalue ()
75 returns.
76 .SH SEE ALSO
77 .BR sem_post (3),
78 .BR sem_wait (3),
79 .BR sem_overview (7)
80 .SH COLOPHON
81 This page is part of release 3.79 of the Linux
82 .I man-pages
83 project.
84 A description of the project,
85 information about reporting bugs,
86 and the latest version of this page,
87 can be found at
88 \%http://www.kernel.org/doc/man\-pages/.