#include <sys/sem.h>
int semop(int semid, struct sembuf *sops,
size_t nsops);
|
The semop() function performs operations on semaphores in a semaphore set. These operations are supplied in a user-defined array of operations.
Parameters
Following is an example of what one of the sembuf structures should look like:
struct sembuf { /* semaphore operation structure */
unsigned short sem_num; /* semaphore number */
short sem_op; /* semaphore operation */
short sem_flg; /* operation flags SEM_UNDO and IPC_NOWAIT */
}
Authorities
Figure 1-13. Authorization Required for semop()
| Object Referred to | Authority Required | errno |
|---|---|---|
| Semaphore, sem_op is negative | Write | EACCES |
| Semaphore, sem_op is positive | Write | EACCES |
| Semaphore, sem_op is zero | Read | EACCES |
Return Value
Error Conditions
If semop() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
An attempt was made to access an object in a way forbidden by its object access permissions.
The thread does not have access to the specified file, directory, component, or path.
If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems.
Operation permission is denied to the calling thread.
The operation would result in suspension of the calling thread but (sem_flg & IPC_NOWAIT) is not zero. (& is a bitwise AND.)
A referenced object is damaged. The object cannot be used.
The value of semid corresponds to a semaphore set that has been marked as damaged by a previous semaphore operation.
In attempting to use an argument in a call, the system detected an address that is not valid.
While attempting to access a parameter passed to this function, the system detected an address that is not valid.
The size of the object would exceed the system allowed maximum size.
The value of sem_num is less than 0 or greater than or equal to the number of semaphores in the set associated with semid.
The semaphore identifier semid has been removed from the system.
The semop() function was interrupted by a signal while the thread was in a wait state.
A parameter passed to this function is not valid.
The value of semid is not a valid semaphore identifier.
The requested operations required additional space on the device and there is no space left. This could also be caused by exceeding the user profile storage limit when creating or transferring ownership of an object.
Insufficient space remains to hold the intended file, directory, or link.
The limit on the number of individual threads requesting a SEM_UNDO would be exceeded.
The value of an argument is too small, or a result too large.
An operation would cause a semval to overflow the system-imposed limit, or an operation would cause a semaphore adjustment value to overflow the system-imposed limit.
The operation failed because of an unknown system state. See any messages in the job log and correct any errors that are indicated, then retry the operation.
Error Messages
None.
Usage Notes
Related Information
Example
For an example of using this function, see Using Semaphores and Shared Memory in Appendix A, Examples.
| Top | Interprocess Communication APIs | APIs by category |
| [Information Center Home Page | Feedback ] | [Legal | AS/400 Glossary] |