Each semaphore has a non-negative value and supports wait and post operations. The semop system call implements both operations.
First parameter specifies a semaphore set identifier,
Second parameter is an array of struct sembuf elements, which specify the operations you want to perform.
The fields of struct sembuf are listed:
sem_num is the semaphore number in the semaphore set on which the operation is performed.
sem_op is an integer that specifies the semaphore operation.
sem_flg is a flag value. Specify IPC_NOWAIT to prevent the operation from blocking; if the operation would have blocked, the call to semop fails instead. If you specify
SEM_UNDO, Linux automatically undoes the operation on the semaphore when the process exits.
The third parameter is the length of this array.
The following http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/sem_pv.ccode (see Fig. 1.2.3) illustrates wait and post operations for a binary semaphore.
Figure 6:
Wait and Post Operations for a Binary Semaphore