Cogs and Levers A blog full of technical stuff

Unix IPC: Semaphores

Semaphores can simplify access to shared resources. The following snippet will show you how to create a semaphore set and destroy it.

key_t key;
int semid;

/* get an IPC key */
key = ftok("filename", 'E');
/* create the new semaphore set */
semid = semget(key, 10, 0666 | IPC_CREAT);

/* destroy the semaphore */
semctl(semid, 0, IPC_RMID);

Further reading