Manual Page Result
0
Command: sem_open | Section: 3 | Source: Digital UNIX | File: sem_open.3.gz
sem_open(3) Library Functions Manual sem_open(3)
NAME
sem_open - Opens/creates a named semaphore for use by a process
(P1003.1b)
SYNOPSIS
#include <semaphore.h>
sem_t *sem_open (
const char *name,
int oflag, ...);
PARAMETERS
name Points to the string naming the semaphore object.
oflag Controls whether the semaphore is created or only accessed by
the call to sem_open. The O_CREAT and O_EXCL flag bits may be
set in oflag.
DESCRIPTION
Use the sem_open function to establish the connection between a named
semaphore and a process. Subsequently, the calling process can refer-
ence the semaphore by using the address returned from the call. The
semaphore is available in subsequent calls to sem_wait, sem_trywait,
sem_post, and sem_getvalue functions. The semaphore remains usable by
the process until the semaphore is closed by a successful call to the
sem_close function.
The oflag flag controls whether the semaphore is created or only ac-
cessed by the call to sem_open. The O_CREAT and O_EXCL flag bits may
be set in oflag as follows:
O_CREAT This flag is used to create a semaphore if it does not
already exist. The O_CREAT argument requires additional
arguments: mode of type mode_t, and value of type un-
signed int. After the semaphore is created, other
processes can open the semaphore by calling sem_open
with the same value for the name argument.
The semaphore's user ID is set to the user ID of the process and the
semaphore's group ID is set to a system default group or to the group
ID of the process. The semaphore's permission bits shall be set to the
value of the mode argument, except for those set in the file mode cre-
ation mask of the process.
O_EXCL If O_EXCL and O_CREAT are set, sem_open will fail if a
semaphore of the same name already exists.
RETURN VALUES
On successful completion, this function opens the semaphore and returns
the semaphore's descriptor. Otherwise, the function returns -1 and
sets errno to indicate the error.
ERRORS
The sem_open function fails under the following conditions:
[EACCES] The named semaphore exists and the permissions
specified by oflag are denied, or the namedsema-
phore does not exist and the permissions specified
by oflag are denied.
[EEXIST] O_CREAT and O_EXCL are set and the named semaphore
already exists.
[EINTR] The sem_open operation was interrupted by a signal.
[EINVAL] The sem_open operation is not supported for the
given name. Or, O_CREAT was specified in oflag and
value wa greater than {SEM_VALUE_MAX}.
[EMFILE] Too many semaphore descriptors or file descriptors
are currently in use by this process.
[ENAMETOOLONG] The length of the name string exceeds {PATH_MAX},
or a pathname component is longer than {NAME_MAX}
while {_POSIX_NO_TRUNC} is in effect.
[ENFILE] Too many semaphores are currently open in the sys-
tem.
[ENOENT] O_CREAT is not set and the named semaphore does not
exist.
[ENOSPC] There is insufficient space for the creation of the
new named semaphore.
RELATED INFORMATION
Functions: sem_close(3), sem_post(3), sem_trywait(3), sem_unlink(3),
sem_wait(3) delim off
sem_open(3)