SHMGET(2) System Calls Manual SHMGET(2)
shmget - get shared memory segment identifier
int shmget(key, size, shmflg)
int size, shmflg;
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:
o key is equal to IPC_PRIVATE.
o 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:
o 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.
o The low-order 9 bits of shm_perm.mode are set equal to the low-order
9 bits of shmflg.
o shm_segsz is set equal to the value of size.
o shm_lpid, shm_nattch, shm_atime, and shm_dtime are set equal to 0.
o 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 associ-
ated with it. The data structure is referred to as shmid_ds and con-
tains 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, Jan. 1, 1970 */
shm_perm is an ipc_perm structure that specifies the shared memory
operation permission (see below). This structure includes the follow-
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 identi-
fier. shm_lpid is the process ID of the last process that performed a
shmop(2) operation. shm_nattch is the number of processes that cur-
rently 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.
shmget() returns a non-negative shared memory identifier on success.
On failure, it returns -1 and sets errno to indicate the error.
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_CREAT) && (shmflg & IPC_EXCL) ) 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 sys-
tem-imposed limit on the maximum number of allowed
shared memory identifiers system wide would be exceeded.
ipcrm(1), ipcs(1), intro(2), shmctl(2), shmop(2)
21 January 1990 SHMGET(2)