Go to the previous, next section.
char *shmat(int shmid, char *shmaddr, int shmflg);
int shmdt(char *shmaddr);
shmid: [in] the shared memory identificator.
shmaddr: [in] the start of the shared memory.
shmflg: [in] some flags (see description).
shmat
attaches a shared memory identificator to a memory range in
the task address space. If shmaddr is zero the range where to
attach the shared memory is choosen by the system. If shmaddr is
not zero and the flag SHM_RND
is specified, the address is
rounded down at a multiple of SHMBLA
. In any other cases, the
address must be page alligned.
If the flag SHM_RDONLY
is specified the task must have read
privileges to the segment and it is attached for reading only.
Otherwise, the task must have read and write privileges on the segment
and it is attached for reading and writing. The same segment may be
attached more than once is the same address space with different flags.
On success, the following members of the shmid_ds
structure of
the segment are modified:
shm_atime
shm_lpid
shm_nattch
shmdt
detaches shared memory segments attached by shmat
.
The shmaddr parameter must be the same value returned by the
shmat
that attached the segment.
On success, the following members of the shmid_ds
structure of
the segment are modified:
shm_dtime
shm_lpid
shm_nattch
Attached memory segments are inherited through the fork
call.
They are detached after a exec
or exit
call.
On success shmat
returns the address of the new memory segment
and shmdt
returns zero. On error, both calls return -1, and set
errno
. The possibles values of errno
are:
for shmat
:
EACCESS
: not enough privileges on the segment.
EINVAL
: shmid or shmaddr invalid.
ENOMEM
.
for shmdt
: the only possible value is EINVAL
for an
invalid value of shmaddr.
Go to the previous, next section.