HP-UX Reference (11i v1 00/12) - 2 System Calls (vol 5)

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man2/!!!intro.2
________________________________________________________________
___ ___
s
sem_close(2) sem_close(2)
NAME
sem_close - close a named POSIX semaphore
SYNOPSIS
#include <sys/semaphore.h>
int sem_close(sem_t *sem);
DESCRIPTION
sem_close() is used to close a named semaphore. A successful call to sem_close() will do the fol-
lowing: Remove the process’s descriptor for the semaphore referenced by the specified sem_t structure
sem. Remove the semaphore referenced by the specified sem_t structure sem, if the semaphore is marked
for removal by a call to sem_unlink() and there are no other descriptors referencing this semaphore.
When the process’s descriptor for the semaphore referenced by sem is removed, subsequent use of this
semaphore by this process will fail. Descriptors for named semaphores are also removed by processes on
exit. Calling sem_close() does not affect other processes referencing the same semaphore.
To use this function, link in the realtime library by specifying -lrt on the compiler or linker command
line.
EXAMPLES
The following call to sem_close() will close a named semaphore referred to by sem by removing the
process’s descriptor to the semaphore and removing the semaphore if it is marked for removal by a previ-
ous
sem_unlink() and there are no descriptors referencing it.
sem_close(sem);
RETURN VALUE
If the semaphore was closed and the descriptors referencing it were removed, sem_close() returns 0 to
the caller.
If the semaphore could not be closed, the call returns -1 and sets errno to indicate the error.
ERRORS
sem_close() fails and does not perform the requested operation if the following condition is encoun-
tered:
[EINVAL] The argument sem is not a valid named semaphore.
SEE ALSO
sem_init(2), sem_open(2), sem_unlink(2), <semaphore.h>.
STANDARDS CONFORMANCE
sem_close() : POSIX
Section 2278 1 HP-UX Release 11i: December 2000
___
___