p Each operation (specified in .Va sem_op ) is applied to semaphore number .Va sem_num in the set of semaphores specified by .Fa semid . The value of .Va sem_op determines the action taken in the following way: l -bullet t .Va sem_op is less than 0. The current process is blocked until the value of the semaphore is greater than or equal to the absolute value of .Va sem_op . The absolute value of .Va sem_op is then subtracted from the value of the semaphore, and the calling process continues. Negative values of .Va sem_op are thus used to enter critical regions. t .Va sem_op is greater than 0. Its value is added to the value of the specified semaphore. This is used to leave critical regions. t .Va sem_op is equal to 0. The calling process is blocked until the value of the specified semaphore reaches 0. .El
p The behaviour of each operation is influenced by the flags set in .Va sem_flg in the following way: l -tag -width IPC_NOWAITX t Dv IPC_NOWAIT In the case where the calling process would normally block, waiting for a semaphore to reach a certain value, .Dv IPC_NOWAIT makes the call return immediately, returning a value of -1 and setting .Va errno to .Er EAGAIN . t SEM_UNDO Keep track of the changes that this call makes to the value of a semaphore, so that they can be undone when the calling process terminates. This is useful to prevent other processes waiting on a semaphore to block forever, should the process that has the semaphore locked terminate in a critical section. .El .Sh RETURN VALUES Upon successful completion, a value of 0 is returned. Otherwise, -1 is returned and the global variable .Va errno is set to indicate the error. .Sh ERRORS .Fn semop will fail if: l -tag -width Er t Bq Er EINVAL There is no semaphore associated with .Fa semid .
p The semaphore set was removed while the process was waiting for one of its semaphores to reach a certain value. t Bq Er EACCES The calling process has no permission to access the specified semaphore set. t Bq Er E2BIG The value of .Fa nsops is too big. The maximum is defined as .Dv MAX_SOPS in .Aq Pa sys/sem.h . t Bq Er EFBIG .Va sem_num in one of the sem_buf structures is less than 0, or greater than the actual number of semaphores in the set specified by .Fa semid . t Bq Er ENOSPC .Dv SEM_UNDO was requested, and there is not enough space left in the kernel to store the unfo information. t Bq Er EAGAIN The requested operation can not immediately be performed, and .Dv IPC_NOWAIT was set in .Va sem_flg . t Bq Er EFAULT .Fa sops points to an illegal address. .El .Sh SEE ALSO .Xr semctl 2 , .Xr semget 2 .Sh BUGS In case of a removed semaphore identifier, .Va errno should be set to .Er EIDRM , but .Nx does not define that error.