Section: POSIX Programmer's Manual (3P)
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
--- get an XSI shared memory segment
int shmget(key_t key, size_t size, int shmflg);
function operates on XSI shared memory (see the Base Definitions volume of POSIX.1-2017,
, Shared Memory Object).
It is unspecified whether this function interoperates with the
realtime interprocess communication facilities defined in
function shall return the shared memory identifier associated with
A shared memory identifier, associated data structure, and shared
memory segment of at least
are created for
if one of the following is true:
is equal to IPC_PRIVATE.
does not already have a shared memory identifier associated with it and
(shmflg &IPC_CREAT) is non-zero.
Upon creation, the data structure associated with the new shared memory
identifier shall be initialized as follows:
The values of
are set to the effective user ID and effective group ID,
respectively, of the calling process.
The low-order nine bits of
are set to the low-order nine bits of
The value of
is set to the value of
The values of
are set to 0.
The value of
is set to the current time, as described in
Section 2.7.1, IPC General Description.
When the shared memory segment is created, it shall be initialized
with all zero values.
Upon successful completion,
shall return a non-negative integer, namely a shared memory identifier;
otherwise, it shall return -1 and set
to indicate the error.
function shall fail if:
A shared memory identifier exists for
but operation permission as specified by the low-order nine bits of
would not be granted; see
Section 2.7, XSI Interprocess Communication.
A shared memory identifier exists for the argument
but (shmflg &IPC_CREAT) &&(shmflg &IPC_EXCL) is non-zero.
A shared memory segment is to be created and the value of size is
less than the system-imposed minimum or greater than the
No shared memory segment is to be created and a shared memory
segment exists for
but the size of the segment associated with it is less than
A shared memory identifier does not exist for the argument
and (shmflg &IPC_CREAT) is 0.
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.
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.
The following sections are informative.
The POSIX Realtime Extension defines alternative interfaces for interprocess
communication. Application developers who need to use IPC should
design their applications so that modules using the IPC routines
, XSI Interprocess Communication
can be easily modified to use the alternative interfaces.
, XSI Interprocess Communication,
The Base Definitions volume of POSIX.1-2017,
Section 3.346, Shared Memory Object,
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see