SEMCTL(2) | System Calls Manual | SEMCTL(2) |
semctl
— control
operations on a semaphore set
Standard C Library (libc, -lc)
#include
<sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
int
semctl
(int
semid, int semnum,
int cmd,
...);
The
semctl
()
system call performs the operation indicated by cmd on
the semaphore set indicated by semid. A fourth
argument, a union semun arg, is required for certain
values of cmd. For the commands that use the
arg argument, union semun must
be defined as follows:
union semun { int val; /* value for SETVAL */ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ u_short *array; /* array for GETALL & SETALL */ };
_WANT_SEMUN
before
including sys/sem.h to use the system definition of
union semun.
Commands are performed as follows:
IPC_STAT
IPC_SET
GETVAL
SETVAL
GETPID
GETNCNT
GETZCNT
GETALL
SETALL
The struct semid_ds is defined as follows:
struct semid_ds { struct ipc_perm sem_perm; /* operation permission struct */ u_short sem_nsems; /* number of sems in set */ time_t sem_otime; /* last operation time */ time_t sem_ctime; /* last change time */ /* Times measured in secs since */ /* 00:00:00 GMT, Jan. 1, 1970 */ };
On success, when cmd is one of
GETVAL
, GETPID
,
GETNCNT
or GETZCNT
,
semctl
() returns the corresponding value; otherwise,
0 is returned. On failure, -1 is returned, and errno
is set to indicate the error.
The semctl
() system call will fail if:
EINVAL
]EINVAL
]EPERM
]EACCES
]ERANGE
]SETVAL
or SETALL
attempted to set a semaphore outside the
allowable range [0 .. SEMVMX
].SETALL
may update some semaphore elements
before returning an error.
July 9, 2020 | Debian |