#include <sys/sem.h> int semctl(int semid, int semnum, int cmd, ...);
|
The semctl() function provides semaphore control operations as specified by cmd on the semaphore specified by semnum in the semaphore set specified by semid.
Parameters
Note: Before Version 3 Release 6 of OS/400, the Common Programming APIs (CPA) Toolkit/400 support for semctl() required the use of the semun structure for this fourth parameter. With support for semaphores in OS/400, use of semun is not required and is not recommended when passing an integer value. If the optional fourth parameter is an integer, IPC expects it to directly follow the third parameter in storage. However, if the semun structure is used to pass the integer value, the value is aligned on a 16-byte boundary, which might not directly follow the third parameter. Therefore, the value used by IPC for the fourth parameter might not be the value intended by the caller, and unexpected results could occur.
The cmd parameter can have one of the following values:
IPC_SET can be performed only by a thread with appropriate privileges or one that has an effective user ID equal to the value of sem_perm.cuid or sem_perm.uid in the semid_ds data structure associated with semid.
Authorities
Figure 1-11. Authorization Required for semctl()
| Object Referred to | Authority Required | errno |
|---|---|---|
| Semaphore, get the value of (cmd = GETVAL) | Read | EACCES |
| Semaphore, set the value of (cmd = SETVAL) | Write | EACCES |
| Semaphore, get last process to operate on (cmd = GETPID) | Read | EACCES |
| Semaphore, get number of threads waiting for value to increase (cmd = GETNCNT) | Read | EACCES |
| Semaphore, get number of threads waiting for value to reach zero (cmd = GETZCNT) | Read | EACCES |
| Semaphore set, get value of each semaphore (cmd = GETALL) | Read | EACCES |
| Semaphore set, set value of each semaphore (cmd = SETALL) | Write | EACCES |
| Semaphore set, retrieve state information (cmd = IPC_STAT) | Read | EACCES |
| Semaphore set, set state information (cmd = IPC_SET) | See Note | EPERM |
| Semaphore set, remove (cmd = IPC_RMID) | See Note | EPERM |
| Note: To set semaphore set information or to remove a semaphore set, the thread must be the owner or creator of the semaphore set, or have appropriate privileges. |
Return Value
Error Conditions
If semctl() 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.
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.
A parameter passed to this function is not valid.
One of the following has occurred:
You must have appropriate privileges or be the owner of the object or other resource to do the requested operation.
The parameter cmd is equal to IPC_RMID or IPC_SET and both of the following are true:
The value of an argument is too small, or a result too large.
The parameter cmd is equal to SETVAL, and the value to which semval is to be set is greater than the system-imposed maximum.
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] |