#include <sys/shm.h> void *shmat(int shmid, const void *shmaddr, int shmflg);
The shmat() function attaches to the shared memory segment specified by shmid and returns the address of the shared memory segment.
The address specified by shmaddr is only used when shmat() is called from a program that uses data model *LLP64 and attaches to a teraspace shared memory segment. Otherwise the address specified by shmaddr is ignored and the actual shared memory segment address is returned regardless of the value of shmaddr.
The system maintains status information about a shared memory segment which can be retrieved with the shmctl() function. When a shared memory segment is successfully attached, the system sets the members of the shmid_ds structure as follows:
Authorization Required for shmat()
Object Referred to | Authority Required | errno |
---|---|---|
Shared memory segment to be attached in read/write memory | Read and Write | EACCES |
Shared memory segment to be attached in read-only memory in a process's teraspace. | Read | EACCES |
value | shmat() was successful. The value returned is a pointer to the shared memory segment associated with the specified identifier. |
NULL | shmat() was not successful. The errno variable is set to indicate the error. |
If shmat() 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.
Operation permission is denied to the calling thread.
Shared memory operations are not permitted because the QSHRMEMCTL system value is set to 0.
The shared memory segment is to be attached in read/write mode and the calling thread does not read and write permission to the shared memory segment.
The shared memory segment is to be attached in read-only mode and the calling thread does not read permission to the shared memory segment.
A damaged object was encountered.
Address already in use.
An attempt was made to attach to a teraspace shared memory segment with the SHM_MAP_FIXED_NP attribute and the address range is not available in the teraspace of the current job.
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.
The shmid parameter is not a valid shared memory identifier.
Operation not supported.
The operation, though supported in general, is not supported for the requested object or the requested arguments.
The SHM_RDONLY flag is set in the shmflg parameter. Read-only shared memory segments are not supported for nonteraspace shared memory segments and for shared memory segments created with the SHM_MAP_FIXED_NP attribute.
Storage allocation request failed.
A function needed to allocate storage, but no storage is available.
The available data space is not large enough to accommodate the shared memory segment.
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 |