O'Reilly logo

Advanced UNIX Programming by Warren W. Gay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating and Accessing Semaphore Sets

A semaphore set is created or accessed by using the semget(2) system call. Its function synopsis is as follows:

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

int semget(key_t key, int nsems, int flags);

The semget(2) function requires an IPC key value in the argument key, and permissions and flags in the argument flag. The argument nsems indicates how many semaphores you want to create in this set.

Like msgget(3), the key argument may be an IPC key or the value IPC_PRIVATE for a set of semaphores without a key value.

The flags argument should contain the permission bits to assign to the created set and the flag bit IPC_CREAT. The flag IPC_EXCL will force an error to be returned if the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required