Destroying Semaphore Sets

When a semaphore set is no longer required, it must be explicitly destroyed. This is necessary because semaphores are not destroyed when a process exits. This is accomplished with the semctl(2) function:

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

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

The argument semid contains the IPC ID of the semaphore set that was created or accessed by semget(2). The argument semnum identifies which semaphore in the set to operate upon when only one semaphore is being accessed. The argument cmd must contain a valid command macro constant that specifies the operation to be performed on the semaphore or semaphore set. The fourth argument is required for some semctl(2) ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.