SEMCTL(2) | System Calls Manual | SEMCTL(2) |
semctl
— control
operations on a semaphore set
#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 is
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 */ };
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 */ struct sem *sem_base; /* pointer to first semaphore in set */ u_short sem_nsems; /* number of sems in set */ time_t sem_otime; /* last operation time */ long sem_pad1; /* SVABI/386 says I need this here */ time_t sem_ctime; /* last change time */ /* Times measured in secs since */ /* 00:00:00 GMT, Jan. 1, 1970 */ long sem_pad2; /* SVABI/386 says I need this here */ long sem_pad3[4]; /* SVABI/386 says I need this here */ };
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:
EACCES
]EINVAL
]EINVAL
]EPERM
]ERANGE
]SETVAL
or SETALL
attempted to set a semaphore outside the
allowable range [0 .. SEMVMX
].#include
<sys/types.h>
#include
<sys/ipc.h>
#include
<sys/sem.h>
The include files
<sys/types.h>
and
<sys/ipc.h>
are
necessary.
SETALL
may update some semaphore elements
before returning an error.
September 12, 1995 | macOS 14.6 |