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

NAME

6       semget - get set of semaphores
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <sys/ipc.h>
11       #include <sys/sem.h>
12
13       int semget(key_t key, int nsems, int semflg);
14
15

DESCRIPTION

17       The  semget() function returns the semaphore identifier associated with
18       key.
19
20
21       A semaphore identifier and associated data structure and set containing
22       nsems  semaphores (see Intro(2)) are created for key if one of the fol‐
23       lowing is true:
24
25           o      key is equal to IPC_PRIVATE.
26
27           o      key does not already have a semaphore identifier  associated
28                  with it, and (semflg&IPC_CREAT) is true.
29
30
31       On creation, the data structure associated with the new semaphore iden‐
32       tifier is initialized as follows:
33
34           o      sem_perm.cuid, sem_perm.uid, sem_perm.cgid, and sem_perm.gid
35                  are  set  equal to the effective user ID and effective group
36                  ID, respectively, of the calling process.
37
38           o      The access permission bits of sem_perm.mode are set equal to
39                  the access permission bits of semflg.
40
41           o      sem_nsems is set equal to the value of nsems.
42
43           o      sem_otime  is  set  equal to 0 and sem_ctime is set equal to
44                  the current time.
45

RETURN VALUES

47       Upon successful completion, a non-negative integer representing a sema‐
48       phore  identifier  is  returned. Otherwise, −1 is returned and errno is
49       set to indicate the error.
50

ERRORS

52       The semget() function will fail if:
53
54       EACCES    A semaphore identifier exists for key, but operation  permis‐
55                 sion  (see  Intro(2)) as specified by the low-order 9 bits of
56                 semflg would not be granted.
57
58
59       EEXIST    A  semaphore  identifier  exists  for  key  but  both   (sem‐
60                 flg&IPC_CREAT) and (semflg&IPC_EXCL) are both true.
61
62
63       EINVAL    The  nsems  argument  is  either  less  than or equal to 0 or
64                 greater than the system-imposed limit. See NOTES.
65
66                 A semaphore identifier exists for key, but the number of sem‐
67                 aphores  in the set associated with it is less than nsems and
68                 nsems is not equal to 0.
69
70
71       ENOENT    A semaphore identifier does  not  exist  for  key  and  (sem‐
72                 flg&IPC_CREAT) is false.
73
74
75       ENOSPC    A  semaphore  identifier  is  to  be  created but the system-
76                 imposed limit on the maximum number of allowed semaphores  or
77                 semaphore  identifiers  system-wide  would  be  exceeded. See
78                 NOTES.
79
80

ATTRIBUTES

82       See attributes(5) for descriptions of the following attributes:
83
84
85
86
87       ┌─────────────────────────────┬─────────────────────────────┐
88       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
89       ├─────────────────────────────┼─────────────────────────────┤
90       │Interface Stability          │Standard                     │
91       └─────────────────────────────┴─────────────────────────────┘
92

SEE ALSO

94       ipcrm(1),  ipcs(1),   rctladm(1M),   Intro(2),   semctl(2),   semop(2),
95       setrctl(2), ftok(3C), attributes(5), standards(5)
96

NOTES

98       The  system-imposed  limit  on  the  value of the nsems argument is the
99       maintained on  a  per-process  basis  using  the  process.max-sem-nsems
100       resource control.
101
102
103       The  system-imposed  limit  on  the  number of semaphore identifiers is
104       maintained  on  a  per-project  basis  using  the   project.max-sem-ids
105       resource  control.  The   zone.max-sem-ids  resource  control limis the
106       total number of semaphore identifiers that can be allocated by a zone.
107
108
109       See rctladm(1M) and setrctl(2) for  information  about  using  resource
110       controls.
111
112
113
114SunOS 5.11                        14 Aug 2006                        semget(2)
Impressum