Copyright (C) 2000-2012 |
GNU Info (ipc.info)semopsemop ----- Operations on semaphore arrays are performed by calling semop : int semop (int semid, struct sembuf *sops, unsigned nsops); * semid : id obtained by a call to semget. * sops : array of semaphore operations. * nsops : number of operations in array (0 < nsops < SEMOPM). * returns : semval for last operation. -1 on failure. Operations are described by a structure sembuf: struct sembuf ushort sem_num; /* semaphore index in array */ short sem_op; /* semaphore operation */ short sem_flg; /* operation flags */ The value `sem_op' is to be added (signed) to the current value semval of the semaphore with index sem_num (0 .. nsems -1) in the set. Flags recognized in sem_flg are IPC_NOWAIT and SEM_UNDO. Two kinds of operations can result in wait: 1. If sem_op is 0 (read operation) and semval is non-zero, the process sleeps on a queue waiting for semval to become zero or returns with error EAGAIN if (IPC_NOWAIT | sem_flg) is true. 2. If (sem_op < 0) and (semval + sem_op < 0), the process either sleeps on a queue waiting for semval to increase or returns with error EAGAIN if (sem_flg & IPC_NOWAIT) is true. The array sops is first read in and preliminary checks performed on the arguments. The operations are parsed to determine if any of them needs write permissions or requests an undo operation. The operations are then tried and the process sleeps if any operation that does not specify IPC_NOWAIT cannot go through. If a process sleeps it repeats these checks on waking up. If any operation that requests IPC_NOWAIT, cannot go through at any stage, the call returns with errno set to EAGAIN. Finally, operations are committed when all go through without an intervening sleep. Processes waiting on the zero_queue or increment_queue are awakened if any of the semval's becomes zero or is incremented respectively. Errors: E2BIG : nsops > SEMOPM. EACCES : Do not have permission for requested (read/alter) access. EAGAIN : An operation with IPC_NOWAIT specified could not go through. EFAULT : The array sops is not accessible. EFBIG : An operation had semnum >= nsems. EIDRM : The resource was removed. EINTR : The process was interrupted on its way to a wait queue. EINVAL : nsops is 0, semid < 0 or unused. ENOMEM : SEM_UNDO requested. Could not allocate space for undo structure. ERANGE : sem_op + semval > SEMVMX for some operation. automatically generated by info2www version 1.2.2.9 |