sem_close Subroutine

Purpose

Closes a named semaphore.

Library

Standard C Library (libc.a)

Syntax

#include <semaphore.h>

int sem_close (sem)
sem_t *sem;

Description

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.

Parameters

Item Description
sem Indicates the semaphore to be closed.

Return Values

Upon successful completion, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error.

Error Codes

The sem_close subroutine fails if:
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.