sem_open(2) DG/UX R4.11MU05 sem_open(2)
NAME
semopen - create or access a named semaphore
SYNOPSIS
#include <semaphore.h>
semt *semopen (*name, oflag, protectionmode, value)
char *name;
int oflag;
modet protectionmode;
unsigned int value;
where:
name A null-terminated string naming the semaphore.
oflag Open intent and open behavior flags.
protectionmode The standard nine permission bits. This parameter is
only used when the semaphore is created.
value The initial value to assign to the semaphore. This
parameter is only used when the semaphore is created.
DESCRIPTION
Use semopen(2) to create or attach to a named semaphore.
The semopen(2) function establishes a connection between a named
semaphore and a process. Following a successful call to semopen(2),
the process may reference the semaphore associated with name by using
the address returned from the call. This address may be used in
subsequent calls to semwait(2), semtrywait(2), and sempost(2).
The name argument points to a string naming the semaphore. The name
argument must conform to the construction rules for a pathname. The
name does not, however, represent a file. Therefore whether the name
has the format of an absolute or relative pathname is not relevant.
The name argument as it appears will be the name of the semaphore.
After the semaphore named name has been created by semopen(2), other
processes can connect to the semaphore by calling semopen(2) with
the same value of name.
Once the semaphore has been successfully opened, the semaphore
remains usable by the process until the semaphore is closed by a
successful call to semclose(2), exit(2), or exec(2). Semaphores are
inherited on a fork(2).
The oflag argument controls whether the semaphore is created or
merely accessed by the call to semopen(2). The semantics of the
oflag follow the same rules as in the open(2) system call. Namely,
O_CREAT will access the semaphore, first creating it if it does not
already exist. O_CREAT | O_EXCL will create the semaphore only if it
does not already exist. The semaphore must be created with read and
write intent allowed.
When a new named semaphore is created, its user ID and group ID are
set to the effective user ID and group ID of the creating process.
The semaphore's permission bits are set to the value of the mode
argument, except those set in the file mode creation mask of the
process. These permission bits and owner IDs are checked each time a
process attempts to attach to the semaphore.
The value specified with this call affects the availability of the
semaphore. A successful lock operation, with semwait(2) or
semtrywait(2), decrements the value and sempost(2) increments it.
If the value is 0, the semaphore is unavailable. In this case,
semwait(2) blocks until the semaphore becomes available whereas
semtrywait(2) returns with an error. Typical initial values
specified with semopen(2) are 0 or 1.
A named semaphore remains in the system until it is rebooted, or
until both of the following occur:
* A process that knows the semaphore's name calls semunlink(2).
(The process need not be attached to the semaphore.)
* All processes attached to the semaphore call semclose(2),
exit(2), or exec(2).
A process may have at most SEM_NSEMS_MAX named semaphores open at
once. Use sysconf(2) with argument _SC_SEM_NSEMS_MAX to get this
system value.
Information about all of the named semaphores on the system can be
retrieved using dgpseminfo(2).
Note
* This routine is based on POSIX realtime extension document P1003.4
draft 14. It is therefore subject to change.
* Compilation of a source file using this routine requires that
feature macro _POSIX4_DRAFT_SOURCE be defined. This feature macro
is not enabled by any other feature macro, nor does it enable any
other feature macro.
* The compiled routine must be linked to library librte.a.
RETURN VALUE
If successful, semopen returns the address of the semaphore. If
unsuccessful, it returns -1 and sets ERRNO to one of the following:
EACCES Permission to create or access the semaphore is denied.
EEXIST O_CREAT and O_EXCL are set, but the semaphore already exists.
EFAULT Unable to access one of the parameters.
EINTR The semopen(2) operation was interrupted by a signal.
EINVAL Unable to create the semaphore.
EINVAL name, or value, is not valid.
EMFILE Too many semaphores are currently in use by this process.
ENAMETOOLONG
name contains more than NAME_MAX characters.
ENOENT sem does not exist and oflag does not have O_CREAT set.
ENOSPC The calling process already has SEM_NSEMS_MAX named
semaphores open.
ENOSPC There is insufficient space for the creation of the new named
semaphore.
SEE ALSO
semclose(2), semwait(2), semtrywait(2), sempost(2),
semunlink(2), seminit(2), dgpseminfo(2), sysconf(2).
Licensed material--property of copyright holder(s)