semctl(2)
NAME
semctl − semaphore control operations
SYNTAX
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
int semctl(semid, semnum, cmd, arg)
int semid, cmd, semnum;
union semun {
int val;
struct semid_ds ∗buf;
ushort ∗array;
} arg;
DESCRIPTION
The semctl system call provides a variety of semaphore control operations as specified by cmd.
The following commands are executed with respect to the semaphore specified by semid and semnum:
GETVAL Returns the value of semval. For further information, see intro(2).
SETVAL Sets the value of semval to arg.val. When this cmd is successfully executed, the semadj value corresponding to the specified semaphore in all processes is cleared.
GETPID Returns the value of sempid.
GETNCNT Returns the value of semncnt.
GETZCNT Returns the value of semzcnt.
The following commands return and set, respectively, every semval in the set of semaphores.
GETALL Places semvals into array pointed to by arg.array.
SETALL Sets semvals according to the array pointed to by arg.array. When this cmd is successfully executed, the semadj values corresponding to each specified semaphore in all processes are cleared.
The following commands are also available:
IPC_STAT Places the current value of each member of the data structure associated with semid into the structure pointed to by arg.buf. For further information, see intro(2).
IPC_SET Sets the value of the following members of the data structure associated with semid to the corresponding value found in the structure pointed to by arg.buf:
sem_perm.uid
sem_perm.gid
sem_perm.mode /∗ only low 9 bits ∗/
This cmd can only be executed by a process that has an effective user ID equal to either that of superuser or to the value of sem_perm.uid in the data structure associated with semid.
IPC_RMID Removes the semaphore identifier specified by semid from the system and destroys the set of semaphores and data structure associated with it. This cmd can only be executed by a process that has an effective user ID equal either to that of superuser or to the value of sem_perm.uid in the data structure associated with semid.
RETURN VALUE
Upon successful completion, the value returned depends on the cmd:
GETVAL Returns the value of semval.
GETPID Returns the value of sempid.
GETNCNT Returns the value of semncnt.
GETZCNT Returns the value of semzcnt.
Otherwise, if unsuccessful, returns a −1, and the global variable errno indicates the error code.
DIAGNOSTICS
The semctl call will fail if:
[EINVAL] The specified semid is not a valid semaphore identifier.
[EINVAL] The specified semnum is less than zero or greater than sem_nsems.
[EINVAL] The specified cmd is not a valid command.
[EACCES] Operation permission is denied to the calling process. For further information, see intro(2).
[ERANGE] The specified cmd is either SETVAL or SETALL, and the value to which semval is to be set is greater than the system imposed maximum.
[EPERM] The specified cmd is either IPC_RMID or IPC_SET, and the effective user ID of the calling process is not that of the superuser or the value of sem_perm.uid in the data structure associated with semid.
[EFAULT] The arg.buf points to an illegal address.