Go to the previous, next section.

semctl

SYNOPSIS

int semctl(int semid, int semnun, int cmd, union semun arg);

PARAMETERS

semid: [in] the semaphore set to manipulate.

semnum: [in] the semaphore in the set to manipulate (0 is the first).

cmd: [in] the operation to perform.

arg: [in out] an argument to the operation (see description).

DESCRIPTION

Manipulates a semaphore set or members of a semaphore set. The possible values for cmd are:

IPC_STAT
gets some information on the semaphore set. The calling task must have read access to the semaphore set.

IPC_SET
modify some members of the semid_ds structure of a semaphore in the set. The members that can be modified are: sem_perm.uid, sem_perm.gid, and the lower 9 bits of sem_perm.mode. The calling task must be the owner or the creator of the semaphore set or the superuser. The sem_ctime field of the set is updated to the current time.

IPC_RMID
removes the semaphore set and awakens the process blocked on operations performed on that set. Only the creator or the owner of the set or the superuser may use this option.

GETALL
returns the semval value of all semaphore in an array.

GETNCNT
returns the number of processes waiting for the value of a specific semaphore in the semaphore set to increase. The calling task must have read privileges on the semaphore set.

GETPPID
returns the pid of the last process to have executed a semaphore opreation a specific semaphore of the semaphore set. The calling task must have read privileges on the semaphore set.

GETVAL
returns the value of a specific semaphore in the semaphore set. The calling task must have read privileges on the semaphore set.

GETZCNT
returns the number of processes waiting for the value of a specific semaphore in the semaphore set to be zero. The calling task must have read privileges on the semaphore set.

SETALL
sets the value of all semaphore in the semaphore set. The calling task must have alter privileges on the semaphore set.

SETVAL
sets the value of a specific semaphore in the semaphore set. The calling task must have alter privileges on the semaphore set.

RETURN VALUE

On success, with cmd equals to:

GETNCNT
the number of waiting tasks (see description).

GETPID
the task pid (see description).

GETVAL
the value of the semaphore.

GETZCNT
the number of waiting tasks (see description).

For other values of cmd, it returns zero. On error, the call returns -1 and errno is set to one of the following values:

Go to the previous, next section.