shmat() - attach shared memory segment
#include <sys/shm.h>
void *shmat(int shmid, const void *shmaddr, int shmflg);
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 shmflag 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 <shm.h>.
To specify the address, make shmaddr non-NULL and:
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 shmflag:
The header file <sys/shm.h> includes <sys/ipc.h>.
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.
The shmat(2) function can fail for the following reasons:
See shmctl(2).
shmctl(2)
shmdt(2),
shmget(2)