SEMCTL(2) | System Calls Manual | SEMCTL(2) |
semctl
— semaphore
control operations
#include
<sys/sem.h>
int
semctl
(int
semid, int semnum,
int cmd,
union semun arg);
The
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). arg 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
IPC_SET
and
IPC_STAT
commands is defined as follows in
<sys/sem.h>
:
struct semid_ds { struct ipc_perm sem_perm; /* operation permissions */ struct sem *sem_base; /* semaphore set */ u_short sem_nsems; /* number of sems in set */ time_t sem_otime; /* last operation time */ time_t sem_ctime; /* last change time */ };
The
<sys/ipc.h>
and looks like
this:
struct ipc_perm { 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; /* r/w permission (see chmod(2)) */ u_short seq; /* sequence # (to generate unique msg/sem/shm id) */ key_t key; /* user specified msg/sem/shm key */ };
semctl
()
provides the following operations:
GETVAL
SETVAL
GETPID
GETNCNT
GETZCNT
GETALL
SETALL
IPC_STAT
IPC_SET
IPC_RMID
The permission to read or change a message queue (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.
For the 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:
EPERM
]IPC_SET
or
IPC_RMID
and the caller is not the superuser, nor
does the effective UID match either the sem_perm.uid
or sem_perm.cuid fields of the data structure
associated with the message queue.EACCES
]EINVAL
]cmd is not a valid command.
EFAULT
]ERANGE
]SETVAL
or
SETALL
and arg.val or the
values in arg.array are greater than the
system-imposed limit.November 15, 2014 | OpenBSD-5.9 |