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

Using Semaphores

The previous section focused on affecting changes in the semaphore and set attributes, and on obtaining information. This section will cover the aspects of using semaphores to perform the following:

  • Wait operations

  • Notify operations

  • Wait for zero operations

These operations work on the entire set of semaphores or on a subset. You can also operate on individual semaphores in the set according to your application needs.

Semaphore operations are performed by the semop(2) system call. Its function synopsis is as follows:

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

int semop(int semid, struct sembuf array[], unsigned nops);

The argument semid contains the IPC ID of the semaphore set, which is returned by 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