SHMGET(2) 21 January 1990 SHMGET(2)

NAME

shmget - get shared memory segment identifier

SYNOPSIS

#include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h>

int shmget(key, size, shmflg) key_t key; int size, shmflg;

DESCRIPTION

shmget() returns the shared memory identifier associated with key.

A shared memory identifier and associated data structure and shared memory segment of at least size bytes (see intro(2)) are created for key if one of the following are true:

  • key is equal to IPC_PRIVATE.

  • key does not already have a shared memory identifier associated with it, and (shmflg & IPC_CREAT) is ``true''.
  • Upon creation, the data structure associated with the new shared memory identifier is initialized as follows:

  • shm_perm.cuid, shm_perm.uid, shm_perm.cgid, and shm_perm.gid are set equal to the effective user ID and effective group ID, respectively, of the calling process.

  • The low-order 9 bits of shm_perm.mode are set equal to the low-order 9 bits of shmflg.

  • shm_segsz is set equal to the value of size.

  • shm_lpid, shm_nattch, shm_atime, and shm_dtime are set equal to 0.

  • shm_ctime is set equal to the current time.
  • A shared memory identifier (shmid) is a unique positive integer created by a shmget(2) system call. Each shmid has a segment of memory (referred to as a shared memory segment) and a data structure associated with it. The data structure is referred to as shmid_ds and contains the following members:

    struct ipc_perm shm_perm; /** operation permission struct **/ int shm_segsz; /** size of segment **/ ushort shm_cpid; /** creator pid **/ ushort shm_lpid; /** pid of last operation **/ short shm_nattch; /** number of current attaches **/ time_t shm_atime; /** last attach time **/ time_t shm_dtime; /** last detach time **/ time_t shm_ctime; /** last change time **/
    /** Times measured in secs since **/
    /** 00:00:00 GMT+1, Jan. 1, 1970 **/

    shm_perm is an ipc_perm structure that specifies the shared memory operation permission (see below). This structure includes the following members:

    ushort cuid; /** creator user id **/ ushort cgid; /** creator group id **/ ushort uid; /** user id **/ ushort gid; /** group id **/ ushort mode; /** r/w permission **/

    shm_segsz specifies the size of the shared memory segment. shm_cpid is the process ID of the process that created the shared memory identifier. shm_lpid is the process ID of the last process that performed a shmop(2) operation. shm_nattch is the number of processes that currently have this segment attached. shm_atime is the time of the last shmat operation, shm_dtime is the time of the last shmdt operation, and shm_ctime is the time of the last shmctl(2) operation that changed one of the members of the above structure.

    RETURN

    shmget() returns a non-negative shared memory identifier on success. On failure, it returns -1 and sets errno to indicate the error.

    ERRORS

    EACCES
    A shared memory identifier exists for key but operation permission (see intro(2)) as specified by the low-order 9 bits of shmflg would not be granted.

    EEXIST
    A shared memory identifier exists for key but ( (shmflg & IPC_CREATS) && ( shmflg & IPC_EXCLS) ) is ``true''.

    EINVAL
    size is less than the system-imposed minimum or greater than the system-imposed maximum. A shared memory identifier exists for key but the size of the segment associated with it is less than size and size is not equal to zero.

    ENOENT
    A shared memory identifier does not exist for key and (shmflg & IPC_CREAT) is ``false''.

    ENOMEM
    A shared memory identifier and associated shared memory segment are to be created but the amount of available physical memory is not sufficient to fill the request.

    ENOSPC
    A shared memory identifier is to be created but the system-imposed limit on the maximum number of allowed shared memory identifiers system wide would be exceeded.

    SEE

    ipcrm(1), ipcs(1), intro(2), shmctl(2), shmop(2)

    SHMGET(2) 21 January 1990 SHMGET(2)

    Manpage converter © AXL