SEMCTL(2) | System Calls Manual | SEMCTL(2) |
semctl
—
#include <sys/sem.h>
int
semctl
(int
semid, int semnum,
int cmd,
...);
semctl
() system call provides a number of control
operations on the semaphore specified by semnum and
semid. The operation to be performed is specified in
cmd (see below). The fourth argument is optional and
depends upon the operation requested. If required, it is a union of the
following fields:
int val; /* value for SETVAL */ struct semid_ds *buf; /* buffer for IPC_{STAT,SET} */ u_short *array; /* array for GETALL & SETALL */
The semid_ds structure used in the
IPC_SET
and IPC_STAT
commands is defined in
<sys/sem.h>
and contains the
following members:
struct ipc_perm sem_perm; /* operation permissions */ unsigned short sem_nsems; /* number of sems in set */ time_t sem_otime; /* last operation time */ time_t sem_ctime; /* last change time */
The ipc_perm structure used inside the
semid_ds structure is defined in
<sys/ipc.h>
and contains the
following members:
uid_t cuid; /* creator user id */ gid_t cgid; /* creator group id */ uid_t uid; /* user id */ gid_t gid; /* group id */ mode_t mode; /* permission (lower 9 bits) */
semctl
() provides the following
operations:
GETVAL
SETVAL
semctl
().GETPID
GETNCNT
GETZCNT
GETALL
SETALL
semctl
().IPC_STAT
semctl
().IPC_SET
semctl
(). This operation can
only be executed by the super-user, or a process that has an effective
user id equal to either sem_perm.cuid or
sem_perm.uid in the data structure associated with
the semaphore.IPC_RMID
The permission to read or change a semaphore (see semop(2)) is determined by the sem_perm.mode field in the same way as is done with files (see chmod(2)), but the effective uid can match either the sem_perm.cuid field or the sem_perm.uid field, and the effective gid can match either sem_perm.cgid or sem_perm.gid.
GETVAL
, GETPID
,
GETNCNT
, and GETZCNT
operations, semctl
() returns one of the values
described above if successful. All other operations will make
semctl
() return 0 if no errors occur. Otherwise -1 is
returned and errno set to reflect the error.
semctl
() will fail if:
EACCES
]EFAULT
]EINVAL
]cmd is not a valid command.
EPERM
]IPC_SET
or
IPC_RMID
and the caller is not the super-user, nor
does the effective uid match either the sem_perm.uid
or sem_perm.cuid fields of the data structure
associated with the semaphore.ERANGE
]SETVAL
or
SETALL
and the value to be set is greater than the
system semaphore maximum value.semctl
system call conforms to
X/Open System Interfaces and Headers Issue 5
(“XSH5”).
August 25, 1999 | NetBSD 9.2 |