SHMOP(2) System Calls Manual SHMOP(2)
shmop, shmat, shmdt - shared memory operations
char *shmat(shmid, shmaddr, shmflg)
shmat() maps the shared memory segment associated with the shared mem-
ory identifier specified by shmid into the data segment of the calling
process. Upon successful completion, the address of the mapped segment
The shared memory segment is mapped at the address specified by one of
the following criteria:
o If shmaddr is equal to zero, the segment is mapped at an address
selected by the system. Ordinarily, applications should invoke
shmat() with shmaddr equal to zero so that the operating system may
make the best use of available resources.
o If shmaddr is not equal to zero and (shmflg & SHM_RND) is ``true'',
the segment is mapped at the address given by (shmaddr - (shmaddr
o If shmaddr is not equal to zero and (shmflg & SHM_RND) is ``false'',
the segment is mapped at the address given by shmaddr.
The segment is mapped for reading if (shmflg & SHM_RDONLY) is ``true''
[READ], otherwise it is mapped for reading and writing [READ/WRITE]
shmdt() unmaps from the calling process's address space the shared mem-
ory segment that is mapped at the address specified by shmaddr. The
shared memory segment must have been mapped with a prior shmat() func-
tion call. The segment and contents are retained until explicitly
removed by means of the IPC_RMID function (see shmctl(2)).
shmat() returns the data segment start address of the mapped shared
memory segment. On failure, it returns -1 and sets errno to indicate
0 on success.
-1 on failure and sets errno to indicate the error.
shmat() will fail and not map the shared memory segment if one or more
of the following are true:
EACCES Operation permission is denied to the calling process
EINVAL shmid is not a valid shared memory identifier.
shmaddr is not equal to zero, and the value of (shmaddr
- (shmaddr modulus SHMLBA)) is an illegal address.
shmaddr is not equal to zero, (shmflg & SHM_RND) is
``false'', and the value of shmaddr is an illegal
EMFILE The number of shared memory segments mapped to the call-
ing process would exceed the system-imposed limit.
ENOMEM The available data space is not large enough to accommo-
date the shared memory segment.
shmdt() will fail and not unmap the shared memory segment if:
EINVAL shmaddr is not the data segment start address of a
shared memory segment.
ipcrm(1), ipcs(1), intro(2), execve(2V), exit(2V), fork(2V), shmctl(2),
21 January 1990 SHMOP(2)