shmctl64()--Perform Shared Memory Control Operations (64-Bit Enabled)
Syntax
#include <sys/shm.h> int shmctl64(int shmid, int cmd, struct shmid_ds64 *buf);
Service Program Name: QP0ZUSHR
Default Public Authority: *USE
Threadsafe: Yes
The shmctl64() function allows the caller to control the shared memory segment specified by the shmid parameter.
The shmctl64() function is enabled for large (64-bit) shared memory segments. It can operate on teraspace shared memory segments larger than 4 294 967 295 bytes (4GB minus 1 byte). It also provides additional functionality not available via the shmctl() function.
A shared memory segment is controlled by setting the cmd parameter to one of the following values:
- IPC_RMID (0x00000000)
- Remove the shared memory segment identifier shmid from the system and
destroy the shared memory segment.
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.
- IPC_SET (0x00000001)
- Set the user ID of the owner, the group ID of the owner, and the permissions
for the shared memory segment to the values in the
shm_perm.uid, shm_perm.gid, and
shm_perm.mode members of the
shmid_ds64 data structure pointed to by *buf.
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.
- IPC_STAT (0x00000002)
- Store the current value of each member of the shmid_ds64 data structure into the structure pointed to by *buf. The IPC_STAT command requires read permission to the shared memory segment.
- SHM_SIZE (0x00000006)
- Set the size of the shared memory segment using the shm_segsz
member of the shmid_ds64 data structure pointed to by
*buf. This value may be larger or smaller than the current size. This
command is valid for nonteraspace shared memory segments and for teraspace
shared memory segments created using the SHM_RESIZE_NP option on the
shmget() or shmget64() function. The maximum size to which a nonteraspace shared memory segment
may be expanded is 16 773 120 bytes (16 MB minus 4096 bytes).
The maximum size of a resizable teraspace shared memory segment is 268 435 456
bytes (256 MB).
The SHM_SIZE command can be run only by a thread with appropriate privileges or a thread 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.
If a shared memory segment is resized to a smaller size, other threads using the memory that is being removed from the shared memory segment may experience memory exceptions when accessing that memory.
- SHM_PAGESIZE (0x000000C8)
- Set the page size of the storage backing the teraspace shared memory segment
using the shm_pagesize field of the shmid_ds64
data structure pointed to by *buf. The shm_pagesize
field is interpreted as a page size in bytes. This command is only valid
for teraspace shared memory segments. Changing the page size of a
nonteraspace shared memory segment will fail with the [ENOTSUP] error.
This command must be called after the teraspace shared memory segment has been created but before any process has attached to the teraspace shared memory segment. Setting the page size of a teraspace shared memory segment after it has been attached to a process will fail with the [EBUSY] error.
Valid values for the shm_pagesize field are:
- SHM_4KB_PAGESIZE (0x0000000000001000): Use a 4KB (4096 bytes) page size. This is the default page size for teraspace shared memory segments when they are created.
- SHM_64KB_PAGESIZE (0x0000000000010000): Use a 64KB (65536 bytes) page size. This page size is only supported on systems with IBM® POWER5+™ or later hardware.
Setting the page size to a value that is not valid or not supported will fail with the [EINVAL] error.
The SHM_PAGESIZE command can be run only by a thread with appropriate privileges or a thread that has an effective user ID equal to the user ID of the owner or the user ID of the creator of the teraspace shared memory segment.
Parameters
- shmid
- (Input) Shared memory identifier, a positive integer. It is returned by the
shmget() or shmget64() function and is used to identify the shared memory segment on which to
perform the control operation.
- cmd
- (Input) Command, the control operation to perform on the shared memory
segment. Valid values are listed above.
- buf
- (I/O) Buffer, the pointer to the shmid_ds64 structure to be used to get or
set shared memory information.
The members of the shmid_ds64 structure are as follows:
struct ipc_perm shm_perm | The members of the ipc_perm structure
are as follows:
|
||||||||||
pid_t shm_lpid | The process ID of the last job to attach to or detach from the segment using shmat() or shmdt(). | ||||||||||
pid_t shm_cpid | The process ID of the job that created the segment using shmget() or shmget64(). | ||||||||||
shmatt_t shm_nattch | The number of jobs attached to the segment. | ||||||||||
size64_t shm_segsz | The size of the segment in bytes. | ||||||||||
char shm_reserved1[4] | Reserved. This field must be set to binary zero on input. | ||||||||||
time_t shm_atime | The time the last job attached to the segment using shmat(). | ||||||||||
char shm_reserved2[4] | Reserved. This field must be set to binary zero on input. | ||||||||||
time_t shm_dtime | The time the last job detached from the segment using shmdt(). | ||||||||||
char shm_reserved3[4] | Reserved. This field must be set to binary zero on input. | ||||||||||
time_t shm_ctime | The time the last job changed the segment using shmctl() or shmctl64(). | ||||||||||
psize_t shm_pagesize | The page size of the storage backing the segment. | ||||||||||
char shm_reserved4[24] | Reserved. This field must be set to binary zero on input. |
Authorities
Authorization Required for shmctl64()
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 |
Shared memory segment for which page size information is set (cmd = SHM_PAGESIZE) | See Note | EPERM |
Note: To set shared memory segment information, to remove a shared memory segment, to resize a shared memory segment, or to set the page size of a shared memory segment, the thread must be the owner or creator of the shared memory segment or have appropriate privileges.
Return Value
0 | shmctl64() was successful. |
-1 | shmctl64() was not successful. The errno variable is set to indicate the error. |
Error Conditions
If shmctl64() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
- [EACCES]
-
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.
- [EBUSY]
-
Resource busy.
An attempt was made to use a system resource that is not available at this time.
The cmd parameter is SHM_PAGESIZE and the shared memory segment has been attached to a process.
- [EDAMAGE]
-
A damaged object was encountered.
The shared memory segment has been damaged by a previous shared memory operation.
- [EFAULT]
-
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.
- [EINVAL]
-
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:
- The shmid parameter is not a valid shared memory identifier.
- The cmd parameter is not a valid command.
- The cmd parameter is SHM_SIZE, and the teraspace shared memory segment cannot be resized because it was not created by specifying SHM_RESIZE_NP on the shmflg parameter of shmget() or shmget64().
- The cmd parameter is SHM_SIZE, and the new size is not valid for the shared memory segment.
- The cmd parameter is SHM_PAGESIZE, and the page size is not valid or not supported for the shared memory segment.
- [ENOMEM]
-
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.
- [ENOTSUP]
-
Operation not supported.
The operation, though supported in general, is not supported for the requested object or the requested arguments.
The SHM_PAGESIZE command is not supported on a nonteraspace shared memory segment.
- [EPERM]
-
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, IPC_SET, SHM_SIZE, or SHM_PAGESIZE and both of the following are true:
- the calling thread does not have the appropriate privileges.
- the effective user ID of the calling thread is not equal to the user ID of the owner or the user ID of the creator of the shared memory segment.
- [EUNKNOWN]
-
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.
Error Messages
None.
Usage Notes
- "Appropriate privileges" is defined to be *ALLOBJ special authority. If the
user profile under which the thread is running does not have *ALLOBJ special
authority, the thread does not have appropriate privileges.
Related Information
- The <sys/shm.h> file (see
Header Files for UNIX®-Type Functions)
- shmat()--Attach Shared Memory Segment to Current
Process
- shmctl()--Perform Shared Memory Control Operations
- shmdt()--Detach Shared Memory Segment from
Calling Process
- shmget()--Get ID of Shared Memory Segment with
Key
- shmget64()--Get ID of Shared Memory Segment with Key (64-Bit Enabled)
Example
For an example of using this function, see Example: Using semaphore set and shared memory functions.
API introduced: V6R1