SHMOP(2) 21 January 1990 SHMOP(2)

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] (see shmctl(2)).

    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

    shmat() returns the data segment start address of the mapped shared memory segment. On failure, it returns -1 and sets errno to indicate the error.

    shmdt() returns:

    0
    on success.

    -1
    on failure and sets errno to indicate the error.

    ERRORS

    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 (see intro(2)).

    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 address.

    EMFILE
    The number of shared memory segments mapped to the calling process would exceed the system-imposed limit.

    ENOMEM
    The available data space is not large enough to accommodate 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.

    SEE

    ipcrm(1), ipcs(1), intro(2), execve(2V), exit(2V), fork(2V), shmctl(2), shmget(2)

    SHMOP(2) 21 January 1990 SHMOP(2)

    Manpage converter © AXL