Go to the previous, next section.

shmat and shmdt

SYNOPSIS

char *shmat(int shmid, char *shmaddr, int shmflg);

int shmdt(char *shmaddr);

PARAMETERS

shmid: [in] the shared memory identificator.

shmaddr: [in] the start of the shared memory.

shmflg: [in] some flags (see description).

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
is set to the current time.

shm_lpid
is set to the current pid.

shm_nattch
is incremented by one.

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
is set to the current time.

shm_lpid
is set to the current pid.

shm_nattch
is decremented by one. If it becomes 0 and the segment is marked for deletionm, the segment is deleted.

Attached memory segments are inherited through the fork call. They are detached after a exec or exit call.

RETURN VALUE

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:

for shmdt: the only possible value is EINVAL for an invalid value of shmaddr.

Go to the previous, next section.