Index of Section 2 Manual Pages
| Interix / SUA | shmat.2 | Interix / SUA |
shmat(2) shmat(2)
shmat()
NAME
shmat() - attach shared memory segment
SYNOPSIS
#include
void *shmat(int shmid, const void *shmaddr, int shmflg);
DESCRIPTION
The shmat(2) function attaches the shared memory segment identified by
shmid to the address space of the calling process. Shmid is the value
returned from shmget(2).) If shmaddr is NULL, the segment is attached at
the first available address. Otherwise, the parameters shmaddr and shmflg
determine the location of the added segment.
The data structure for shared memory segments and the control flags (such
as SHM_RND) are defined in .
To specify the address, make shmaddr non-NULL and:
* if shmflg & SHM_RND is zero, the segment is attached at the address
given by shmaddr.
* if shmflg & SHM_RND is non-zero, the segment is attached at the
address
shmaddr - ((ptrdiff_t)shmaddr%SHMLBA))
where % is the C language modulus (remainder) operator.
Permissions on the shared memory segment are determined by the value of
shmflg:
* If (shmflg & SHM_RDONLY) is zero, and the the calling process has
read and write permission, the segment is attached for reading and
writing.
* If (shmflg & SHM_RDONLY) is non-zero, and the calling process has
read permission, the segment is attached for reading.
The header file includes .
RETURN VALUE
On success, shmat(2) increments the value of shm_nattach in the data
structure and returns the segment's start address.
On failure, shmat(2) returns -1 and sets errno to indicate the error.
ERRORS
The shmat(2) function can fail for the following reasons:
[EACCES]
Permission is denied to the calling process.
[EINVAL]
Shmid is not a valid shared memory identifier, or (if shmaddr is not
NULL) the value of (shmaddr-((pterdiff_t)shmaddr%SHMLBA)) is an
illegal address, or shmaddr is not a valid address.
[EMFILE]
Adding this shared memory segment would exceed the system limit.
[ENOMEM]
The data space is not large enough to accommodate the shared memory
segment.
[ENOSYS]
The function is not implemented.
EXAMPLES
See shmctl(2).
SEE ALSO
shmctl(2)
shmdt(2),
shmget(2)
USAGE NOTES
The shmat function is thread safe.
The shmat function is not async-signal safe.