sem_open(2)sem_open(2)NAMEsem_open - create/open a named POSIX semaphore
SYNOPSISDESCRIPTION
is used to open or create a named semaphore. A successful call to will
create a descriptor for the semaphore specified by name. The pointer
to the semaphore returned by can be used to access the semaphore asso‐
ciated with name in subsequent operations. The name argument points to
a string referring to a semaphore. It should begin with a "/" and shall
conform to pathname rules except that no path component should be "."
or "..".
The oflag argument specifies whether a semaphore is to be created or
not. The following bits in it may be set:
If this flag is set, a new semaphore is created if it does not
already exist.
If this flag is not set, the semaphore should
already exist.
If this flag is set, the call fails if the semaphore already
exists.
This flag is valid only when is also set; other‐
wise, it is ignored.
The mode and value arguments are provided to supply the permissions and
the initial value information necessary for creating a new semaphore.
To use this function, link in the realtime library by specifying on the
compiler or linker command line.
EXAMPLES
The following call to will create a new named semaphore if one does not
exist, which depends on the flags specified in oflag, has the permis‐
sions specified in mode and has an initial value of value.
RETURN VALUE
If the semaphore was created and initialized, returns a pointer to a
structure containing the index of the new descriptor.
If the semaphore could not be created/initialized, the call returns -1
and sets to indicate the error. If the named semaphore is already
opened by the calling process, a descriptor and a structure for the
named semaphore already exists for the calling process. A new descrip‐
tor is not created and a pointer to the existing structure is returned
for this call.
ERRORS
fails and does not perform the requested operation if any of the fol‐
lowing conditions are encountered:
[EACCES] The named semaphore exists and the process does
not have the permissions to open the semaphore as
described by oflag, or the named semaphore does
not exist and the process does not have the per‐
mission to open it.
[EEXIST] The flags and are set in oflag and the named sem‐
aphore exists.
[EINTR] A signal interrupted the operation.
[EINVAL] The argument value is greater than and the flag
was specified in oflag.
[EINVAL] The name argument does not begin with "/" or con‐
tains "." or ".." as a pathname component.
[EMFILE] Too many semaphore descriptors are currently in
use by this process.
[ENAMETOOLONG] The name string is longer than
[ENFILE] There are too many semaphores in the system.
[ENOENT] The flag is not set in oflag and the named sema‐
phore does not exist.
[ENOSPC] There are insufficient resources for the creation
of a new named semaphore.
SEE ALSOsem_close(2), sem_post(2), sem_wait(2), sem_unlink(2), privileges(5),
<semaphore.h>.
STANDARDS CONFORMANCEsem_open(2)