Describes the structures that are used by subroutines that perform semaphore operations.
The /usr/include/sys/sem.h file defines the structures that are used by the semop subroutine and the semctl subroutine to perform various semaphore operations.
The sem structure stores the values that the Commands parameter of the semctl subroutine gets and sets. This structure contains the following fields:
semval | Specifies the operation permission structure of a semaphore. The data type of this field is unsigned short. |
sempid | Specifies the last process that performed a semop subroutine. The data type of this field is pid_t. |
semncnt | Specifies the number of processes awaiting semval > cval. The data type of this field is unsigned short. |
semzcnt | Specifies the number of processes awaiting semval = 0. The data type of this field is unsigned short. |
The sembuf structure stores semaphore information used by the semop subroutine. This structure contains the following fields:
If the semval field is greater than or equal to the absolute value of the sem_op field, the absolute value of the sem_op field is subtracted from the value of the semval field.
If the semval field is less than the absolute value of the sem_op field and the IPC_NOWAIT flag is set, the semop subroutine returns a value of -1 and sets the errno global variable to EAGAIN.
If the value of the semval field is less than the absolute value of the sem_op field and the IPC_NOWAIT flag is not set, the semop subroutine increments the semncnt field associated with the specified semaphore and suspends execution of the calling process until one of the following conditions is met:
The data type of the sem_op field is short.
If this value is set for an operation and the value of the sem_op field is a positive integer, the value of the sem_op field is subtracted from the Semadj value of the calling process.
If this value is set for an operation and the value of the sem_op field is a negative integer, the absolute value of the sem_op field is added to the Semadj value of the calling process. The exit subroutine adds the Semadj value to the value of the semval field of the semaphore when the process terminates.
If the SEM_ORDER flag is not set (the default), the specified operations are performed atomically. That is, none of the semval values in the array are modified until all of the semaphore operations are completed. If the calling process must wait until some semval requirement is met, the semop subroutine does so before performing any of the operations. If any semaphore operation would cause an error to occur, none of the operations are performed.
If the SEM_ORDER flag is set, the operations are performed individually in the order that they appear in the array, regardless of whether any of the operations require the process to wait. If an operation encounters an error condition, the semop subroutine sets the SEM_ERR flag in the sem_flg field of the failing operation; neither the failing operation nor the following operations in the array are performed.
The data type of the sem_flg field is short.
The semid_ds structure stores semaphore status information used by the semctl subroutine and pointed to by the Buffer parameter. This structure contains the following fields:
sem_perm | Specifies the operation permission structure of a semaphore. The data type of this field is struct ipc_perm. |
sem_nsems | Specifies the number of semaphores in the set. The data type of this field is unsigned short. |
sem_otime | Specifies the time at which a semop subroutine was last performed. The data type of this field is time_t. |
sem_ctime | Specifies the time at which this structure was last changed with a semctl subroutine. The data type of this field is time_t. |
The atexit subroutine, exec subroutines, exit subroutine fork subroutine, semctl subroutine, semget subroutine, semop subroutine, sigaction subroutine.
The Header Files Overview defines header files, describes how they are used, and lists several of the header files for which information is provided in this documentation.