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 ...