#include <sys/shm.h> int shmctl(int shmid, int cmd, struct shmid_ds *buf);
The shmctl() function allows the caller to control the shared memory segment specified by the shmid parameter.
A shared memory segment is controlled by setting the cmd parameter to one of the following values:
The IPC_RMID command can be run only by a thread with appropriate privileges or one that has an effective user ID equal to the user ID of the owner or the user ID of the creator of the shared memory segment. The structure pointed to by *buf is ignored and can be NULL.
The IPC_SET command can be run only by a thread with appropriate privileges or one that has an effective user ID equal to the user ID of the owner or the user ID of the creator of the shared memory segment.
The members of the shmid_ds structure are as follows:
struct ipc_perm shm_perm | The members of the ipc_perm structure
are as follows:
|
||||||||||
size_t shm_segsz | The size of the segment in bytes. | ||||||||||
pid_t shm_lpid | The process ID of the last job to attach or detach to the segment using shmat() or shmdt(). | ||||||||||
pid_t shm_cpid | The process ID of the job that created the segment using shmget(). | ||||||||||
int shm_nattch | The number of jobs attached to the segment. | ||||||||||
time_t shm_atime | The time the last job attached to the segment using shmat(). | ||||||||||
time_t shm_dtime | The time the last job detached from the segment using shmdt(). | ||||||||||
time_t shm_ctime | The time the last job changed the segment using shmctl(). |
Authorization Required for shmctl()
Object Referred to | Authority Required | errno |
---|---|---|
Shared memory segment for which state information is retrieved (cmd = IPC_STAT) | Read | EACCES |
Shared memory segment for which state information is set (cmd = IPC_SET) | See Note | EPERM |
Shared memory segment to be removed (cmd = IPC_RMID) | See Note | EPERM |
Shared memory segment to be resized (cmd = SHM_SIZE) | See Note | EPERM |
Note: To set shared memory segment information, to remove a shared memory segment, or to resize a shared memory segment, the thread must be the owner or creator of the shared memory segment or have appropriate privileges.
0 | shmctl() was successful. |
-1 | shmctl() was not successful. The errno variable is set to indicate the error. |
If shmctl() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
Permission denied.
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.
The cmd parameter is IPC_STAT and the calling thread does not have read permission to shared memory segment.
A damaged object was encountered.
The shared memory segment has been damaged by a previous shared memory operation.
The address used for an argument is not correct.
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 value specified for the argument is not correct.
A function was passed incorrect argument values, or an operation was attempted on an object and the operation specified is not supported for that type of object.
An argument value is not valid, out of range, or NULL.
One of the following has occurred:
Storage allocation request failed.
A function needed to allocate storage, but no storage is available.
A shared memory identifier segment is to be resized, but the amount of available physical memory is not sufficient to fulfill the request.
Operation not permitted.
You must have appropriate privileges or be the owner of the object or other resource to do the requested operation.
The cmd parameter is IPC_RMID or IPC_SET and both of the following are true:
Unknown system state.
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.
None.
See Code disclaimer information for information pertaining to code examples.
For an example of using this function, see Using Semaphores and Shared Memory in Examples: APIs.
Top | UNIX-Type APIs | APIs by category |