sem_getvalue(2) sem_getvalue(2)
NAME [Toc] [Back]
sem_getvalue - get the value of a POSIX semaphore
SYNOPSIS [Toc] [Back]
#include <sys/semaphore.h>
int sem_getvalue(sem_t *sem, int *sval);
DESCRIPTION [Toc] [Back]
sem_getvalue() is used to read the value of the semaphore. The value
of the semaphore specified by sem is read, at some unspecified time
during the call, and then stored into sval. If the semaphore value is
<= 0, at that time, the semaphore is considered unavailable. If the
semaphore value is > 0, at that time, the semaphore is considered
available.
If sval is positive, it is equal to the number of locks available on
the semaphore, at the time the semaphore value was read. If sval is
negative, its absolute value is equal to the number of blocked threads
waiting for the semaphore to become available, at the time the
semaphore value was read.
If the specified semaphore referred to by sem is a named semaphore,
then this semaphore must have been opened by the calling process with
sem_open() and the process must have read permission on this
semaphore.
To use this function, link in the realtime library by specifying -lrt
on the compiler or linker command line.
EXAMPLES [Toc] [Back]
The following call to sem_getvalue() will read the value of the
semaphore sem and store it in sval.
sem_getvalue(sem,sval);
RETURN VALUE [Toc] [Back]
A successful call to sem_getvalue() will return 0. Otherwise, the
call to sem_getvalue() will return -1 with errno set to the
appropriate value of the error condition.
ERRORS [Toc] [Back]
sem_getvalue() fails and does not perform the requested operation if
any of the following conditions are encountered:
[EPERM] The calling process does not have the privileges
necessary to read the semaphore.
[EINVAL] The argument sem does not refer to a valid
semaphore.
Hewlett-Packard Company - 1 - HP-UX 11i Version 2: August 2003
sem_getvalue(2) sem_getvalue(2)
SEE ALSO [Toc] [Back]
sem_open(2), <semaphore.h>.
STANDARDS CONFORMANCE [Toc] [Back]
sem_getvalue(): POSIX
Hewlett-Packard Company - 2 - HP-UX 11i Version 2: August 2003 [ Back ] |