Open System Services System Calls Reference Manual (G06.25+, H06.03+)

semget(2) OSS System Calls Reference Manual
The sem_nsems eld is set to the value of the nsems parameter.
The sem_otime eld is set to 0 (zero), and the sem_ctime eld is set equal to the current
time.
The semget() function does not initialize the sem structure associated with each semaphore in
the set. The individual OSS semaphores are initialized by using the semctl() function with the
SETVAL or SETALL value for the cmd parameter.
Key Creation
The key represents a user-designated name for a given semaphore set. Keys are usually selected
by calling the ftok() function before calling the semget() function. The ftok( ) function returns a
key based on a path and an interprocess communications identi
er. This key is then passed to
the semget() function, which returns a semaphore set ID. The semaphore set ID is then used in
calls to the semop() and semctl() functions.
Propagation During Process Creation
Semaphore set IDs attached to a parent process are also attached to a child process. A sema-
phore set cannot be shared when a child process is created in a different processor than that used
by the parent. If a process attempts to create a child process in a different processor while the
parent process has any adjust-on-exit (semadj) value, the process creation fails and errno is set
to [EHLDSEM].
Cleaning Up Semaphores
An OSS semaphore remains allocated until it is removed. Normally, the semctl() function is
used with the IPC_RMID value of the cmd parameter to remove unneeded OSS semaphores.
The HP implementation of OSS environment semaphores does not provide facilities to detect or
avoid deadlocks.
An allocated OSS semaphore set ID is not removed automatically when the last process using it
terminates. Instead, the OSS semaphore set ID becomes inactive. The user must remove inactive
OSS semaphore set IDs to avoid wasting system resources.
The status of OSS semaphore set IDs can be checked with the ipcs command. Inactive OSS
semaphore set IDs can be removed with the ipcrm command.
Semaphore Use Between Environments
OSS and Guardian environment nonprivileged binary semaphores coexist but do not interoperate.
Guardian environment processes cannot use OSS environment function calls for access to OSS
semaphores. OSS environment processes can create and operate on nonprivileged binary sema-
phores through Guardian environment procedure calls.
Use From the Guardian Environment
If called from a Guardian process, the actions of this function are undened and errno is set to
[ENOTOSS].
RETURN VALUES
Upon successful completion, a nonnegative semaphore set ID is returned. Otherwise, the
semget() function returns the value -1 and sets errno to indicate the condition.
ERRORS
If any of the following conditions occurs, the semget() function sets errno to the corresponding
value:
[EACCES] A semaphore set ID already exists for the key parameter, but operation permis-
sion as specied by the low-order nine bits of the semg parameter was not
granted.
716 Hewlett-Packard Company 527186-003