SHMGET(2,L) AIX Technical Reference SHMGET(2,L)
-------------------------------------------------------------------------------
shmget
PURPOSE
Gets shared memory segment.
SYNTAX
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
int shmget (key, size, shmflg)
key_t key;
int size, shmflg;
DESCRIPTION
The shmget system call returns the shared memory identifier associated with the
specified key. The key parameter is either the value IPC_PRIVATE or an IPC key
constructed by the ftok subroutine (or by a similar algorithm). See "stdipc:
ftok" for details about this subroutine. The size parameter specifies the
number of bytes of shared memory required.
The shmflg parameter is constructed by logically ORing one or more of the
following values:
IPC_CREAT Creates the data structure if it does not already exist.
IPC_EXCL Causes the shmget system call to fail if IPC_CREAT is also set and
the data structure already exists.
S_IRUSR Permits the process that owns the data structure to read it.
S_IWUSR Permits the process that owns the data structure to modify it.
S_IRGRP Permits the group associated with the data structure to read it.
S_IWGRP Permits the group associated with the data structure to modify it.
S_IROTH Permits others to read the data structure.
S_IWOTH Permits others to modify the data structure.
The values that begin with S_I- are defined in the sys/stat.h header file and
are a subset of the access permissions that apply to files.
A shared memory identifier, its associated data structure, and a shared memory
segment equal in bytes to the value of the size parameter are created for the
key parameter if one of the following is true:
o The key parameter is equal to IPC_PRIVATE.
o The key parameter does not already have a shared memory identifier
associated with it, and IPC_CREAT is set.
Processed November 7, 1990 SHMGET(2,L) 1
SHMGET(2,L) AIX Technical Reference SHMGET(2,L)
Upon creation, the data structure associated with the new shared memory
identifier is initialized as follows:
o shm_perm.cuid and shm_perm.uid are set equal to the effective user ID of
the calling process.
o shm_perm.cgid and shm_perm.gid are set equal to the effective group ID of
the calling process.
o The low-order nine bits of shm_perm.mode are set equal to the low-order
nine bits of the shmflg parameter.
o shm_segsz is set equal to the value of the size parameter.
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.
Note: In a Transparent Computing Facility cluster, shared memory segments
exist only on the cluster site on which they are created. Consequently,
processes that use shared memory segments cannot be migrated to other
sites and processes on different cluster sites cannot share memory
segments.
RETURN VALUE
Upon successful completion, a shared memory identifier is returned. If shmget
fails, a value of -1 is returned and errno is set to indicate the error.
ERROR CONDITIONS
The shmget system call fails if one or more of the following are true:
EINVAL The size parameter is less than the system-imposed minimum or greater
than the system-imposed maximum.
EACCES A shared memory identifier exists for the key parameter but operation
permission as specified by the low-order nine bits of the shmflg
parameter is not granted.
EINVAL A shared memory identifier exists for key, but the size of the
segment associated with it is less than the size parameter and the
size parameter is not equal to 0.
ENOENT A shared memory identifier does not exist for the key parameter and
IPC_CREAT not set.
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 will be exceeded.
Processed November 7, 1990 SHMGET(2,L) 2
SHMGET(2,L) AIX Technical Reference SHMGET(2,L)
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.
EEXIST A shared memory identifier exists for the key parameter, and both
IPC_CREAT and IPC_EXCL are set.
RELATED INFORMATION
In this book: "shmat," "shmctl," "shmdt," and "stdipc: ftok."
Processed November 7, 1990 SHMGET(2,L) 3