semget.2 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. .\"
  2. .\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
  3. .\"
  4. .\" All rights reserved.
  5. .\"
  6. .\" Redistribution and use in source and binary forms, with or without
  7. .\" modification, are permitted provided that the following conditions
  8. .\" are met:
  9. .\" 1. Redistributions of source code must retain the above copyright
  10. .\" notice, this list of conditions and the following disclaimer.
  11. .\" 2. Redistributions in binary form must reproduce the above copyright
  12. .\" notice, this list of conditions and the following disclaimer in the
  13. .\" documentation and/or other materials provided with the distribution.
  14. .\"
  15. .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
  16. .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. .\"
  26. .Dd March 4, 2018
  27. .Dt SEMGET 2
  28. .Os
  29. .Sh NAME
  30. .Nm semget
  31. .Nd obtain a semaphore id
  32. .Sh LIBRARY
  33. .Lb libc
  34. .Sh SYNOPSIS
  35. .In sys/sem.h
  36. .Ft int
  37. .Fn semget "key_t key" "int nsems" "int flag"
  38. .Sh DESCRIPTION
  39. Based on the values of
  40. .Fa key
  41. and
  42. .Fa flag ,
  43. .Fn semget
  44. returns the identifier of a newly created or previously existing
  45. set of semaphores.
  46. .\"
  47. .\" This is copied verbatim from the shmget manpage. Perhaps
  48. .\" it should go in a common manpage, such as .Xr ipc 2
  49. .\"
  50. The key
  51. is analogous to a filename: it provides a handle that names an
  52. IPC object.
  53. There are three ways to specify a key:
  54. .Bl -bullet
  55. .It
  56. IPC_PRIVATE may be specified, in which case a new IPC object
  57. will be created.
  58. .It
  59. An integer constant may be specified.
  60. If no IPC object corresponding
  61. to
  62. .Fa key
  63. is specified and the IPC_CREAT bit is set in
  64. .Fa flag ,
  65. a new one will be created.
  66. .It
  67. The
  68. .Xr ftok 3
  69. function
  70. may be used to generate a key from a pathname.
  71. .El
  72. .\"
  73. .\" Likewise for this section, except SHM_* becomes SEM_*.
  74. .\"
  75. .Pp
  76. The mode of a newly created IPC object is determined by ORing these constants
  77. into the
  78. .Fa flag
  79. argument:
  80. .Bl -tag -width 0000
  81. .It Dv 0400
  82. Read access for user.
  83. .It Dv 0200
  84. Alter access for user.
  85. .It Dv 0040
  86. Read access for group.
  87. .It Dv 0020
  88. Alter access for group.
  89. .It Dv 0004
  90. Read access for other.
  91. .It Dv 0002
  92. Alter access for other.
  93. .El
  94. .Pp
  95. If a new set of semaphores is being created,
  96. .Fa nsems
  97. is used to indicate the number of semaphores the set should contain.
  98. Otherwise,
  99. .Fa nsems
  100. may be specified as 0.
  101. .Sh RETURN VALUES
  102. The
  103. .Fn semget
  104. system call
  105. returns the id of a semaphore set if successful; otherwise, -1
  106. is returned and
  107. .Va errno
  108. is set to indicate the error.
  109. .Sh ERRORS
  110. The
  111. .Fn semget
  112. system call
  113. will fail if:
  114. .Bl -tag -width Er
  115. .\" ipcperm could fail (we are opening to read and write, as it were)
  116. .It Bq Er EACCES
  117. Access permission failure.
  118. .\"
  119. .\" sysv_sem.c is quite explicit about these, so I'm pretty sure
  120. .\" this is accurate
  121. .\"
  122. .It Bq Er EEXIST
  123. IPC_CREAT and IPC_EXCL were specified, and a semaphore set
  124. corresponding to
  125. .Fa key
  126. already exists.
  127. .It Bq Er EINVAL
  128. The number of semaphores requested exceeds the system imposed maximum
  129. per set.
  130. .It Bq Er EINVAL
  131. A semaphore set corresponding to
  132. .Fa key
  133. already exists and contains fewer semaphores than
  134. .Fa nsems .
  135. .It Bq Er EINVAL
  136. A semaphore set corresponding to
  137. .Fa key
  138. does not exist and
  139. .Fa nsems
  140. is 0 or negative.
  141. .It Bq Er ENOSPC
  142. Insufficiently many semaphores are available.
  143. .It Bq Er ENOSPC
  144. The kernel could not allocate a
  145. .Fa "struct semid_ds" .
  146. .It Bq Er ENOENT
  147. No semaphore set was found corresponding to
  148. .Fa key ,
  149. and IPC_CREAT was not specified.
  150. .El
  151. .Sh SEE ALSO
  152. .Xr semctl 2 ,
  153. .Xr semop 2 ,
  154. .Xr ftok 3