1SHMGET(3P)                 POSIX Programmer's Manual                SHMGET(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       shmget — get an XSI shared memory segment
13

SYNOPSIS

15       #include <sys/shm.h>
16
17       int shmget(key_t key, size_t size, int shmflg);
18

DESCRIPTION

20       The shmget() function operates on XSI shared memory (see the Base Defi‐
21       nitions  volume  of POSIX.1‐2017, Section 3.346, Shared Memory Object).
22       It is unspecified whether this function interoperates with the realtime
23       interprocess communication facilities defined in Section 2.8, Realtime.
24
25       The shmget() function shall return the shared memory identifier associ‐
26       ated with key.
27
28       A shared memory identifier, associated data structure, and shared  mem‐
29       ory  segment  of  at least size bytes (see <sys/shm.h>) are created for
30       key if one of the following is true:
31
32        *  The argument key is equal to IPC_PRIVATE.
33
34        *  The argument key does not already have a shared  memory  identifier
35           associated with it and (shmflg &IPC_CREAT) is non-zero.
36
37       Upon creation, the data structure associated with the new shared memory
38       identifier shall be initialized as follows:
39
40        *  The  values  of  shm_perm.cuid,  shm_perm.uid,  shm_perm.cgid,  and
41           shm_perm.gid  are  set to the effective user ID and effective group
42           ID, respectively, of the calling process.
43
44        *  The low-order nine bits of shm_perm.mode are set to  the  low-order
45           nine bits of shmflg.
46
47        *  The value of shm_segsz is set to the value of size.
48
49        *  The  values  of  shm_lpid, shm_nattch, shm_atime, and shm_dtime are
50           set to 0.
51
52        *  The value of shm_ctime is set to the current time, as described  in
53           Section 2.7.1, IPC General Description.
54
55       When the shared memory segment is created, it shall be initialized with
56       all zero values.
57

RETURN VALUE

59       Upon successful completion, shmget() shall return a non-negative  inte‐
60       ger,  namely  a shared memory identifier; otherwise, it shall return -1
61       and set errno to indicate the error.
62

ERRORS

64       The shmget() function shall fail if:
65
66       EACCES A shared memory identifier exists for key but operation  permis‐
67              sion as specified by the low-order nine bits of shmflg would not
68              be granted; see Section 2.7, XSI Interprocess Communication.
69
70       EEXIST A shared memory identifier exists for the argument key but (shm‐
71              flg &IPC_CREAT) &&(shmflg &IPC_EXCL) is non-zero.
72
73       EINVAL A  shared  memory segment is to be created and the value of size
74              is less than the system-imposed minimum or greater than the sys‐
75              tem-imposed maximum.
76
77       EINVAL No  shared  memory  segment is to be created and a shared memory
78              segment exists for key but the size of  the  segment  associated
79              with it is less than size.
80
81       ENOENT A  shared  memory identifier does not exist for the argument key
82              and (shmflg &IPC_CREAT) is 0.
83
84       ENOMEM A shared memory identifier and associated shared memory  segment
85              are  to  be created, but the amount of available physical memory
86              is not sufficient to fill the request.
87
88       ENOSPC A shared memory identifier is to be  created,  but  the  system-
89              imposed  limit  on  the  maximum number of allowed shared memory
90              identifiers system-wide would be exceeded.
91
92       The following sections are informative.
93

EXAMPLES

95       None.
96

APPLICATION USAGE

98       The POSIX Realtime Extension defines alternative interfaces for  inter‐
99       process  communication.  Application  developers  who  need  to use IPC
100       should design their applications so that modules using the IPC routines
101       described  in Section 2.7, XSI Interprocess Communication can be easily
102       modified to use the alternative interfaces.
103

RATIONALE

105       None.
106

FUTURE DIRECTIONS

108       None.
109

SEE ALSO

111       Section 2.7, XSI Interprocess  Communication,  Section  2.8,  Realtime,
112       ftok(), shmat(), shmctl(), shmdt(), shm_open(), shm_unlink()
113
114       The Base Definitions volume of POSIX.1‐2017, Section 3.346, Shared Mem‐
115       ory Object, <sys_shm.h>
116
118       Portions of this text are reprinted and reproduced in  electronic  form
119       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
120       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
121       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
122       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
123       event of any discrepancy between this version and the original IEEE and
124       The Open Group Standard, the original IEEE and The Open Group  Standard
125       is  the  referee document. The original Standard can be obtained online
126       at http://www.opengroup.org/unix/online.html .
127
128       Any typographical or formatting errors that appear  in  this  page  are
129       most likely to have been introduced during the conversion of the source
130       files to man page format. To report such errors,  see  https://www.ker
131       nel.org/doc/man-pages/reporting_bugs.html .
132
133
134
135IEEE/The Open Group                  2017                           SHMGET(3P)
Impressum