Performs a semaphore control operation.
#include <sys/sem.h> int semctl ( int semid, int semnum, int cmd, ...
(IN) Specifies the semaphore identifier for the set (returned from the semget function).
(IN) Specifies the number of semaphores in the set.
(IN) Specifies a semaphore command with one of the following flags:
Flag |
Value |
Description |
---|---|---|
IPC_RMID |
0 |
Removes the semaphore identifier and destroys the semaphore set. |
IPC_SET |
1 |
Sets the access permissions in the ipc_perm structure of the semid_ds structure. |
IPC_STAT |
2 |
Returns the access permissions in the ipc_perm structure of the semid_ds structure. |
GETNCNT |
3 |
Returns the number of threads waiting for the semaphore count to become greater than the current value. |
GETPID |
4 |
Returns the ID of the process from the last semop operation. |
GETVAL |
5 |
Returns the value of the semaphore. The semnum parameter specifies which semaphore. |
GETALL |
6 |
Returns the value of all the semaphores in the set. The optional parameter must point to an array for the values |
GETZCNT |
7 |
Returns the number of threads waiting for the semaphore count to become greater than 0. |
SETVAL |
8 |
Sets the value of the semaphore. The semnum parameter specifies which semaphore in the set. The optional parameter specifies the value. |
SETALL |
9 |
Sets the value of all the semaphores in the set. The optional parameter must point to an array of values. |
(IN) Specifies an optional argument, if needed by the semaphore command. This should be an element in the semun union.
If successful, the value returned depends upon the command.
If unsucessful, returns -1 and sets errno to one of the following:
When you specify the fourth parameter, you should make the explicit assignment prior to calling semctl.