#include <sys/shm.h>
void *shmat(int shmid, const void *shmaddr,
int shmflg);
|
The shmat() function returns the address of the shared memory segment associated with the specified shared memory identifier.
Parameters
The value of the shmflg parameter is either zero or the following constant:
Authorities
Figure 1-14. 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 |
Return Value
Error Conditions
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.
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.
Address already in use.
An attempt was made to attach to a SHM_MAP_FIXED_NP teraspace shared memory segment, but the address range is not available in the teraspace of the current process.
The value of shmid corresponds to a shared memory ID that has been marked as damaged by a previous shared memory 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 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 value of shmid is not a valid shared memory identifier.
The operation, though supported in general, is not supported for the requested object or the requested arguments.
The value of (shmflg & SHM_RDONLY) is not zero. (& is a bitwise AND.) Read-only shared memory segments are not supported for nonteraspace shared memory segments. Read-only shared memory segments are not supported for shared memory segments created using the SHM_MAP_FIXED_NP option of shmget().
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.
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
The IPC implementation has the following restrictions over the X/Open single UNIX specification (formerly Spec 1170) definition:
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] |