Manual Page Result
0
Command: shmget | Section: 2 | Source: Digital UNIX | File: shmget.2.gz
shmget(2) System Calls Manual shmget(2)
NAME
shmget - Returns (and possibly creates) the ID for a shared memory re-
gion
SYNOPSIS
#include <sys/shm.h>
int shmget(
key_t key,
size_t size,
int flags);
If programs are being developed for multiple platforms, application de-
velopers may want to specify #include statements for <sys/types.h> and
<sys/ipc.h> before the one for <sys/shm.h>. The additional #include
statements are not required on DIGITAL UNIX systems or by ISO or X/Open
standards, but may be required on other vendors' systems that conform
to these standards.
STANDARDS
Interfaces documented on this reference page conform to industry stan-
dards as follows:
shmget(): XPG4, XPG4-UNIX
Refer to the standards(5) reference page for more information about in-
dustry standards and associated tags.
PARAMETERS
Specifies the key that identifies the shared memory region. The value
for the key parameter can be IPC_PRIVATE or a random number other than
zero (0). If the value of key is IPC_PRIVATE, it can be used to assure
the return of a new, unused shared memory region. Specifies the mini-
mum number of bytes to allocate for the region. Specifies the creation
flags. Possible values are: If the key specified does not exist, the
shmget() function creates an ID using the specified key.
If the specified key does exist, and IPC_EXCL is not set, the ID
for the specified key is returned.
If the specified key does exist and IPC_EXCL is set, the
shmget() function fails and returns an error. If the key al-
ready exists, the shmget() function fails and returns an error
notification.
DESCRIPTION
The shmget() function returns (and possibly creates) the ID for the
shared memory region identified by the key parameter. If IPC_PRIVATE
is used for the key parameter, the shmget() function returns the ID for
a private (that is, newly created) shared memory region. The flags pa-
rameter supplies creation options for the shmget() function. If the
key parameter does not already exist, the IPC_CREAT flag instructs the
shmget() function to create a new shared memory region for the key and
return the kernel-assigned ID for the region.
After creating a new shared memory region ID, the shmget() function
initializes the shmid_ds structure associated with the ID as follows:
The shm_perm.cuid and shm_perm.uid fields are set equal to the effec-
tive user ID of the calling process. The shm_perm.cgid and
shm_perm.gid fields are set equal to the effective group ID of the
calling process. The low-order nine bits of the shm_perm.mode field
are set equal to the low-order nine bits of flags. The shm_segsz field
is set equal to size. The shm_lpid, shm_nattch, shm_atime, and
shm_dtime fields are all set equal to 0 (zero). The shm_ctime field is
set equal to the current time. [DIGITAL] The shm_cpid field is set to
the process ID of the calling process.
[DIGITAL] To reduce the overhead associated with managing large shared
memory regions among many processes, the DIGITAL UNIX kernel makes use
of shared page tables, also referred to as segmented shared memory
(SSM). When the segment size requested by shmget is greater than or
equal to the value of ssm-threshold (an attribute in /etc/syscon-
figtab), the memory region is managed using shared page tables. When
attaching to such a segment, the segment must always be aligned and
sized correctly. The alignment and size factor is given by the system-
defined SSM_SIZE value (see machine/pmap.h). When the attachment oc-
curs, the segment's memory region is aligned on an SSM_SIZE boundary
and its size is rounded up to the next SSM_SIZE boundary - thus, the
segment size specified by shmget does not need to be a multiple of
SSM_SIZE. (Use of segmented shared memory can be disabled by setting
the ssm-threshold attribute to zero.)
RETURN VALUES
Upon successful completion, a shared memory identifier is returned. If
the shmget() function fails, a value of -1 is returned and errno is set
to indicate the error.
ERRORS
The shmget() function sets errno to the specified values for the fol-
lowing conditions: A shared memory region ID already exists for the key
parameter, but operation permission as specified by the low-order nine
bits of the flags parameter was not granted. A shared memory region ID
already exists for the key parameter, but IPC_CREAT and IPC_EXCL were
used for the flags parameter. The value of the size parameter is less
than the system-defined minimum or greater than the system-defined max-
imum. Or, a shared memory region ID already exists for the key parame-
ter, but the number of bytes allocated for the region is less than size
and size is not equal to 0 (zero). A shared memory region ID does not
exist for the key parameter, and IPC_CREAT was not used for the flags
parameter. An attempt was made to create a shared memory region ID and
its associated shmid_ds structure, but there was not enough physical
memory available. An attempt to create a new shared memory region ID
exceeded the system-wide limit on the maximum number of IDs allowed.
RELATED INFORMATION
Functions: shmat(2), shmctl(2), shmdt(2), sysconfig(8), table(2),
ftok(3)
Files: shmid_ds(4)
Standards: standards(5) delim off
shmget(2)