man.bsd.lv manual page server

Manual Page Search Parameters

SEMCTL(2) System Calls Manual SEMCTL(2)

semctlcontrol operations on a semaphore set

library “libc”

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>

int
semctl(int semid, int semnum, int cmd, ...);

() 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 parameter, 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:

Fetch the semaphore set's struct semid_ds, storing it in the memory pointed to by arg.buf.
Changes the sem_perm.uid, sem_perm.gid, and sem_perm.mode members of the semaphore set's struct semid_ds to match those of the struct pointed to by arg.buf. The calling process's effective uid must match either sem_perm.uid or sem_perm.cuid, or it must have superuser privileges.
Immediately removes the semaphore set from the system. The calling process's effective uid must equal the semaphore set's sem_perm.uid or sem_perm.cuid, or the process must have superuser privileges.
Return the value of semaphore number semnum.
Set the value of semaphore number semnum to arg.val.
Return the pid of the last process to perform an operation on semaphore number semnum.
Return the number of processes waiting for semaphore number semnum's value to become greater than its current value.
Return the number of processes waiting for semaphore number semnum's value to become 0.
Fetch the value of all of the semaphores in the set into the array pointed to by arg.array.
Set the values of all of the semaphores in the set to the values in the array pointed to by arg.array.

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 XSI Interprocess Communication family of functions is also available as an implementation in userspace. To use it, the sysvipcd(8) daemon has to be running.

If the USR_SYSVIPC variable is set in a process' environment, the process and its children will use the userspace implementation.

Semctl() will fail if:

[]
No semaphore set corresponds to semid.
[]
semnum is not in the range of valid semaphores for given semaphore set.
[]
The calling process's effective uid does not match the uid of the semaphore set's owner or creator.
[]
Permission denied due to mismatch between operation and mode of semaphore set.

semget(2), semop(2)

The DragonFly specific userspace implementation (see ENVIRONMENT) was written by Larisa Grigore.

January 4, 2014 DragonFly-5.6.1