1shmget(2)                        System Calls                        shmget(2)
2
3
4

NAME

6       shmget - get shared memory segment identifier
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/ipc.h>
11       #include <sys/shm.h>
12
13       int shmget(key_t key, size_t size, int shmflg);
14
15

DESCRIPTION

17       The  shmget()  function returns the shared memory identifier associated
18       with key.
19
20
21       A shared memory identifier and associated  data  structure  and  shared
22       memory  segment  of  at least size bytes (see Intro(2)) are created for
23       key if one of the following are true:
24
25           o      The key argument is equal to IPC_PRIVATE.
26
27           o      The key argument does not already have a shared memory iden‐
28                  tifier associated with it, and (shmflg&IPC_CREAT) is true.
29
30
31       Upon creation, the data structure associated with the new shared memory
32       identifier is initialized as follows:
33
34           o      The values of  shm_perm.cuid,  shm_perm.uid,  shm_perm.cgid,
35                  and  shm_perm.gid are set equal to the effective user ID and
36                  effective group ID, respectively, of the calling process.
37
38           o      The access permission bits of shm_perm.mode are set equal to
39                  the access permission bits of shmflg. shm_segsz is set equal
40                  to the value of size.
41
42           o      The values of shm_lpid, shm_nattch shm_atime, and  shm_dtime
43                  are set equal to 0.
44
45           o      The shm_ctime is set equal to the current time.
46
47
48       Shared memory segments must be explicitly removed after the last refer‐
49       ence to them has been removed.
50

RETURN VALUES

52       Upon successful  completion,  a  non-negative  integer  representing  a
53       shared  memory  identifier  is  returned. Otherwise, −1 is returned and
54       errno is set to indicate the error.
55

ERRORS

57       The shmget() function will fail if:
58
59       EACCES    A shared memory identifier exists for key but operation  per‐
60                 mission  (see  Intro(2)) as specified by the low-order 9 bits
61                 of shmflg would not be granted.
62
63
64       EEXIST    A shared memory identifier exists  for  key  but  both  (shm‐
65                 flg&IPC_CREAT) and (shmflg&IPC_EXCL) are true.
66
67
68       EINVAL    The  size argument is less than the system-imposed minimum or
69                 greater than the system-imposed maximum. See NOTES.
70
71                 A shared memory identifier exists for key but the size of the
72                 segment  associated with it is less than size and size is not
73                 equal to 0.
74
75
76       ENOENT    A shared memory identifier does not exist for key  and  (shm‐
77                 flg&IPC_CREAT) is false.
78
79
80       ENOMEM    A  shared memory identifier and associated shared memory seg‐
81                 ment are to be created but the amount of available memory  is
82                 not sufficient to fill the request.
83
84
85       ENOSPC    A  shared  memory identifier is to be created but the system-
86                 imposed limit on the maximum number of allowed shared  memory
87                 identifiers system-wide would be exceeded. See NOTES.
88
89

ATTRIBUTES

91       See attributes(5) for descriptions of the following attributes:
92
93
94
95
96       ┌─────────────────────────────┬─────────────────────────────┐
97       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
98       ├─────────────────────────────┼─────────────────────────────┤
99       │Interface Stability          │Standard                     │
100       └─────────────────────────────┴─────────────────────────────┘
101

SEE ALSO

103       rctladm(1M),  Intro(2), setrctl(2), shmctl(2), shmop(2), ftok(3C), get‐
104       pagesize(3C), attributes(5), standards(5)
105

NOTES

107       The project.max-shm-memory resource control restricts the total  amount
108       of  shared  memory  a  project  can  allocate.  The zone.max-shm-memory
109       resource control restricts the total amount of shared memory  that  can
110       be  allocated  by  a  zone. The system-imposed maximum on the size of a
111       shared memory segment is therefore a  function  of  the  sizes  of  any
112       other  shared  memory segments the calling project might have allocated
113       that are still in use, as well as  any  other  shared  memory  segments
114       allocated  and  still  in use by processes in the zone.  For accounting
115       purposes, segment sizes are rounded up to the nearest multiple  of  the
116       system page size. See getpagesize(3C).
117
118
119       The  system-imposed limit on the number of shared memory identifiers is
120       maintained  on  a  per-project  basis  using  the   project.max-shm-ids
121       resource  control.  The zone.max-shm-ids resource control restricts the
122       total number of shared memory identifiers that can be  allocated  by  a
123       zone.
124
125
126       See  rctladm(1M)  and  setrctl(2)  for information about using resource
127       controls.
128
129
130
131SunOS 5.11                        14 Aug 2006                        shmget(2)
Impressum