Closes a named semaphore.
Standard C Library (libc.a)
#include <semaphore.h>
int sem_close (sem)
sem_t *sem;
The sem_close subroutine indicates that the calling process is finished using the named semaphore indicated by the sem parameter. Calling sem_close for an unnamed semaphore (one created by sem_init) returns an error. The sem_close subroutine deallocates (that is, makes available for reuse by a subsequent calls to the sem_open subroutine) any system resources allocated by the system. If the process attempts subsequent uses of the semaphore pointed to by sem, an error is returned. If the semaphore has not been removed with a successful call to the sem_unlink subroutine, the sem_close subroutine has no effect on the state of the semaphore. If the sem_unlink subroutine has been successfully invoked for the name parameter after the most recent call to sem_open with the O_CREAT flag set, when all processes that have opened the semaphore close it, the semaphore is no longer accessible.
Item | Description |
---|---|
sem | Indicates the semaphore to be closed. |
Upon successful completion, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error.
Item | Description |
---|---|
EFAULT | Invalid user address. |
EINVAL | The sem parameter is not a valid semaphore descriptor. |
ENOMEM | Insufficient memory for the required operation. |
ENOTSUP | This function is not supported with processes that have been checkpoint-restart'ed. |