Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ semop(2) — A/UX 3.0.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exec(2)

exit(2)

fork(2)

intro(2)

semctl(2)

semget(2)




semop(2) semop(2)
NAME semop - performs semaphore operations SYNOPSIS #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> int semop(semid, sops, nsops) int semid; struct sembuf *sops; int nsops; DESCRIPTION semop is used to request one or more semaphore operations on one or more semaphores accessible through the same semaphore identifier. Upon successful completion, semop returns the value of the sempaphore prior to the last operation. See ``Status Messages and Values'' later in this manual page. Upon unsuccessful completion, the associated semval value is left unchanged, semop returns -1, and errno is set to indicate one of the conditions listed in ``Status Messages and Values.'' The set of semaphores to be operated upon are those specified through semid and the sen_num member of the operation structure. The set of operations to be performed are those in the array of operation structures referenced by the pointer sops. The number operation structures in the array is given by nsops. Each operation structure contains the following members: short sem_num; /* semaphore number */ short sem_op; /* semaphore operation */ short sem_flg; /* operation flags */ The member sem_op specifies one of three semaphore operations for permissions and structure declarations, as follows (see intro(2): If sem_op is a negative integer, one of the following operations will occur: If the value of semval (see intro(2)) is greater than or equal to the absolute value of sem_op, the absolute value of sem_op is subtracted from the value of semval. Also, if (sem_flg & SEM_UNDO) is true, the absolute value of sem_op is added to the calling process's semadj value (see exit(2)) for the specified semaphore. If semval is less than the absolute value of sem_op and (sem_flg & IPC_NOWAIT) is true, semop returns January 1992 1



semop(2) semop(2)
immediately. If semval is less than the absolute value of sem_op and (sem_flg & IPC_NOWAIT) is false, semop increments the semncnt associated with the specified semaphore and suspend execution of the calling process until one of the following conditions occur: The semaphore value semval becomes greater than or equal to the absolute value of sem_op. When this condition occurs, the value of semncnt associated with the specified semaphore is decremented, the absolute value of sem_op is subtracted from semval, and, if (sem_flg & SEM_UNDO) is true, the absolute value of sem_op is added to the calling process's semadj value for the specified semaphore. The semid for which the calling process is awaiting action is removed from the system (see semctl(2)). When this condition occurs, errno is set equal to EIDRM and a value of -1 is returned. The calling process receives a signal that is to be caught. When this condition occurs, the value of semncnt associated with the specified semaphore is decremented, and the calling process resumes execution in the manner prescribed in signal(3). If sem_op is a positive integer, the value of sem_op is added to semval and, if (sem_flg & SEM_UNDO) is true, the value of sem_op is subtracted from the calling process's semadj value for the specified semaphore. If sem_op is zero, one of the following operations will occur: If semval is zero, semop returns immediately. If semval is not equal to zero and (sem_flg & IPC_NOWAIT) is true, semop returns immediately. If semval is not equal to zero and (sem_flg & IPC_NOWAIT) is false, semop increments the semzcnt associated with the specified semaphore and suspends execution of the calling process until one of the following conditions occurs: The semaphore value semval becomes zero, and the value of semzcnt associated with the specified semaphore is decremented. 2 January 1992



semop(2) semop(2)
The semid for which the calling process is awaiting action is removed from the system. When this condition occurs, errno is set equal to EIDRM and a value of -1 is returned. The calling process receives a signal that is to be caught. When this condition occurs, the value of semzcnt associated with the specified semaphore is decremented and the calling process resumes execution in the manner prescribed in signal(3). STATUS MESSAGES AND VALUES Upon successful completion of all requested semaphore operations, the value of the semaphore member sempid is reset to the process ID of the calling process for each affected semaphore. The return value is the value of the semaphore prior to the last operation. The value -1 is returned by semop when exceptional conditions occur. In such cases the value of semval is not the return value (-1) of semop. A return value of -1 is often due to an error condition that pertains to one or more of the operations specified. Sometimes a return value of -1 is generated because of a special status condition that pertains to a semaphore in general and that is unrelated to the operation specified (see EINTR and EIDRM in the list of error codes later in this section). The errno variable identifies the exception condition that applies. If you obtain a -1 return value from a semop call, you can identify the condition that caused the exception through one of the following errno values: EINTR The semaphore value semop was returned because a signal was received. EIDRM The semaphore value semop was returned because a semid was removed from the system. EINVAL The semaphore value semid is not a valid semaphore identifier. EFBIG The semaphore value sem_num is less than zero or greater than or equal to the number of semaphores in the set associated with semid. January 1992 3



semop(2) semop(2)
E2BIG The semaphore value nsops is greater than the system- imposed maximum. EACCES The operation permission is denied to the calling process (see intro(2)). EAGAIN The operation would result in suspension of the calling process but (sem_flg & IPC_NOWAIT) is true. ENOSPC The limit on the number of individual processes requesting a SEM_UNDO would be exceeded. EINVAL The number of individual semaphores for which the calling process requests a SEM_UNDO would exceed the limit. ERANGE An operation would cause a semval to overflow the system-imposed limit. ERANGE An operation would cause a semadj value to overflow the system-imposed limit. EFAULT The semaphore value sops points to an illegal address. SEE ALSO exec(2), exit(2), fork(2), intro(2), semctl(2), semget(2) 4 January 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026