semop.2
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 2 代码 · 共 307 行
2
307 行
.\" SCCSID: @(#)semop.2 8.1 9/11/90.TH semop 2.SH Namesemop \- semaphore operations.SH Syntax.nf.B #include <sys/types.h>.B #include <sys/ipc.h>.B #include <sys/sem.h>.PP.B int semop (\fIsemid, sops, nsops\fP).B int \fIsemid\fP;.B struct sembuf *\fIsops[]\fP;.B int \fInsops\fP;.fi.SH Description.NXB "semop system call".NXB "semaphore" "operations".NXA "semop system call" "semctl system call".NXA "semop system call" "semget system call"The.PN semopsystem callis used to atomically perform anarray of semaphore operations on the set ofsemaphores associated with the semaphore identifier specified by .PN semid .The.I sopsis a pointer to the array of semaphore-operation structures.The.I nsopsis the number of such structures in the array.The contents of each structureincludes the following members:.EXshort sem_num; /* semaphore number */short sem_op; /* semaphore operation */short sem_flg; /* operation flags */.EE.PPEach semaphore operation specified by.I sem_opis performed on the corresponding semaphore specified by.PN semidand.IR sem_num ..PPThe.I sem_opspecifies one of three semaphore operations as follows:.PP.B 1.If.I sem_opis a negative integer, one of the following occurs: .IP \(bu 4If .I semvalis greater than or equal to the absolute value of.I sem_op,the absolute value of.I sem_opis subtracted from .I semval. For further information, see .MS intro 2 .Also, if .RI ( sem_flg& SEM_UNDO)is true, the absolute value of.I sem_opis added to the calling process's .I semadj value for the specified semaphore.For further information, see .MS exit 2 ..IP \(buIf .I semvalis less than the absolute value of.I sem_opand .RI ( sem_flg& IPC_NOWAIT)is true, .PN semopreturns immediately..IP \(buIf .I semvalis less than the absolute value of.I sem_opand .IR ( sem_flg& IPC_NOWAIT )is false, .PN semopincrements the .I semncnt associated with the specified semaphore andsuspend execution of the callingprocess until one of the following occurs:.IP \(buIf the.I semvalbecomes greater thanor equal to the absolute value of .I sem_op.When this occurs, the value ofsemncnt associated with the specifiedsemaphore is decremented, the absolute value of .I sem_opis subtracted from .I semval,and if .RI ( sem_flg& SEM_UNDO)is true, the absolute value of.I sem_opis added to the calling process's.I semadj value for the specified semaphore..IPThe .PN semidfor which the callingprocess is awaiting action is removedfrom the system. For further information, see.MS semctl 2 .When this occurs, .I errnois set equal to EIDRM, and a value of \-1 is returned..PPThe calling process receives a signalthat is to be caught. When this occurs,the value of .I semncnt associated with the specified semaphore is decremented,and the calling process resumes executionin the manner prescribed in .MS signal 3 ..PP.B 2.If.I sem_opis a positive integer, the value of .I sem_opis added to .I semvaland, if .RI ( sem_flg& SEM_UNDO)is true, the value of .I sem_opis subtracted from the calling process's .I semadj value for the specified semaphore. .PP.B 3.If.I sem_op is zero, one of the following occurs:.IP \(bu 4If .I semvalis zero,.PN semopreturns immediately..IP \(buIf .I semvalis not equal to zero and .RI ( sem_flg& IPC_NOWAIT)is true,.PN semopreturns immediately..IP \(buIf .I semvalis not equal to zero and .RI ( sem_flg& IPC_NOWAIT)is false, .PN semopincrements the .I semzcnt associated with the specified semaphore and suspendexecution of the calling process, untilone of the following occurs:.IPThe.I semvalbecame zero, at which timethe value of .I semzcnt associated with the specified semaphore is decremented..IPThe .PN semidfor which the calling processis awaiting action is removed from thesystem. When this occurs,.I errnois set equal to EIDRM, and a value of \-1 is returned..PPThe calling process receives a signalthat is to be caught. When this occurs,the value of .I semzcntassociated withthe specified semaphore is decremented,and the calling process resumes executionin the manner prescribed in .MS signal 3 ..RE.PPUpon successful completion, the value of .I sempid for each semaphorespecified in the array pointed to by.I sopsis set equal to the process ID of the calling process..SH Return ValuesUpon successful completion, a value of 0 is returned.Otherwise, a value of \-1 is returned, and .I errnois set to indicate the error..SH Diagnostics.NXR "semop system call" "diagnostics"The.PN semopfails if any of the following is true for any of thesemaphore operations specified by .IR sops:.TP 15[EINVAL]The.I sempidis not a valid semaphore identifier. .TP 15[EFBIG]The.I sem_numis less than zero or greater than orequal to the number of semaphoresin the set associated with.PN semid ..TP 15[E2BIG]The.I nsopsis greater than the system-imposed maximum. .TP 15[EACCESS]Operation permission is denied to the calling process.For further information, see .MS errno 2 . .TP 15[EAGAIN]The operation would result in suspension of the calling process, but .RI ( sem_flg&IPC_NOWAIT)is true. .TP 15[ENOSPC]The limit on the number of individual processes requesting an SEM_UNDOwould be exceeded. .TP 15[EINVAL]The number of individual semaphoresfor which the calling process request aSEM_UNDOwould exceed the limit. .TP 15[ERANGE]An operation would cause a .I semvalto overflow the system-imposed limit..TP 15[ERANGE]An operation would cause a .I semadj value to overflow the system-imposed limit. .TP 15[EFAULT]The.I sopspoints to an illegal address. .TP 15[EINTR]The.PN semopreturns due to the receipt of a signal..TP[EIDRM]The.PN semidhas been removed from the system..SH See Alsoexecve(2), exit(2), fork(2), semctl(2), semget(2), signal(3).NXE "semop system call".NXE "semaphore" "operations"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?