SHMOP
Section: System Calls (2)
Updated: 21 November 1987
Index
Return to Main Contents
NAME
shmop, shmat, shmdt - shared memory operations
SYNOPSIS
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
char *shmat(shmid, shmaddr, shmflg)
int shmid;
char *shmaddr;
int shmflg;
int shmdt(shmaddr)
char *shmaddr;
DESCRIPTION
shmat()
maps the shared memory segment associated with the shared memory identifier
specified by
shmid
into the data segment of the calling process. Upon successful completion,
the address of the mapped segment is returned.
The shared memory segment is mapped at the address specified
by one of the following criteria:
- *
-
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.
- *
-
If
shmaddr
is not equal to zero and
(shmflg &
SHM_RND)
is ``true'', the segment is mapped at the address given by
(shmaddr -
(shmaddr modulus
SHMLBA)).
- *
-
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 memory segment that is mapped at the address specified by
shmaddr.
The shared memory segment must have been mapped with a prior
shmat()
function call. The segment and contents are retained until explicitly
removed by means of the
IPC_RMID
function (see
shmctl(2)).
RETURN VALUES
Upon successful completion, the return values are as follows:
- *
-
shmat()
returns the data segment start address of the mapped shared memory segment.
- *
-
shmdt()
returns a value of 0.
Otherwise, a value of -1 is returned and
errno
is set to indicate the error.
ERRORS
shmat()
will fail and not map the shared memory segment if one or more of the
following are true:
- EINVAL
-
shmid
is not a valid shared memory identifier.
- EACCES
-
Operation permission is denied to the calling process (see
intro(2)).
- ENOMEM
-
The available data space
is not large enough to accommodate the shared memory segment.
- EINVAL
-
shmaddr
is not equal to zero, and the value of
(shmaddr -
(shmaddr modulus
SHMLBA))
is an illegal address.
- EINVAL
-
shmaddr
is not equal to zero,
(shmflg &
SHM_RND)
is ``false'', and the value of
shmaddr
is an illegal address.
- EMFILE
-
The number of shared memory segments mapped to the calling process would
exceed the system-imposed limit.
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.
SEE ALSO
execve(2),
exit(2),
fork(2),
intro(2),
shmctl(2),
shmget(2)
BUGS
The System V shared memory functions are implemented at user level on top
of the mmap(2) interface. Not all the System V functionality is
implemented.
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUES
-
- ERRORS
-
- SEE ALSO
-
- BUGS
-
This document was created by
man2html,
using the manual pages.
Time: 04:51:43 GMT, January 31, 2023