shmat()

NAME

shmat() - attach shared memory segment

SYNOPSIS

#include <sys/shm.h>

void *shmat(int shmid, const void *shmaddr, int shmflg);

DESCRIPTION

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:

Permissions on the shared memory segment are determined by the value of shmflag:

The header file <sys/shm.h> includes <sys/ipc.h>.

RETURN VALUE

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.

ERRORS

The shmat(2) function can fail for the following reasons:

[EACCES]
Permission is denied to the calling process.
[EINVAL]
Shmid is not a valid shared memory identifier, or (if shmaddr is not NULL) the value of (shmaddr-((pterdiff_t)shmaddr%SHMLBA)) is an illegal address, or shmaddr is not a valid address.
[EMFILE]
Adding this shared memory segment would exceed the system limit.
[ENOMEM]
The data space is not large enough to accommodate the shared memory segment.
[ENOSYS]
The function is not implemented.

EXAMPLES

See shmctl(2).

SEE ALSO

shmctl(2)

shmdt(2),

shmget(2)