logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

semget.3p (5679B)


  1. '\" et
  2. .TH SEMGET "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. semget
  12. \(em get set of XSI semaphores
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <sys/sem.h>
  17. .P
  18. int semget(key_t \fIkey\fP, int \fInsems\fP, int \fIsemflg\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The
  22. \fIsemget\fR()
  23. function operates on XSI semaphores (see the Base Definitions volume of POSIX.1\(hy2017,
  24. .IR "Section 4.17" ", " "Semaphore").
  25. It is unspecified whether this function interoperates with the
  26. realtime interprocess communication facilities defined in
  27. .IR "Section 2.8" ", " "Realtime".
  28. .P
  29. The
  30. \fIsemget\fR()
  31. function shall return the semaphore identifier associated with
  32. .IR key .
  33. .P
  34. A semaphore identifier with its associated
  35. .BR semid_ds
  36. data structure and its associated set of
  37. .IR nsems
  38. semaphores (see
  39. .IR <sys/sem.h> )
  40. is created for
  41. .IR key
  42. if one of the following is true:
  43. .IP " *" 4
  44. The argument
  45. .IR key
  46. is equal to IPC_PRIVATE.
  47. .IP " *" 4
  48. The argument
  49. .IR key
  50. does not already have a semaphore identifier associated with it and
  51. (\fIsemflg\fP &IPC_CREAT) is non-zero.
  52. .P
  53. Upon creation, the
  54. .BR semid_ds
  55. data structure associated with the new semaphore identifier is
  56. initialized as follows:
  57. .IP " *" 4
  58. In the operation permissions structure
  59. .IR sem_perm.cuid ,
  60. .IR sem_perm.uid ,
  61. .IR sem_perm.cgid ,
  62. and
  63. .IR sem_perm.gid
  64. shall be set to the effective user ID and effective group ID,
  65. respectively, of the calling process.
  66. .IP " *" 4
  67. The low-order 9 bits of
  68. .IR sem_perm.mode
  69. shall be set to the low-order 9 bits of
  70. .IR semflg .
  71. .IP " *" 4
  72. The variable
  73. .IR sem_nsems
  74. shall be set to the value of
  75. .IR nsems .
  76. .IP " *" 4
  77. The variable
  78. .IR sem_otime
  79. shall be set to 0 and
  80. .IR sem_ctime
  81. shall be set to the current time, as described in
  82. .IR "Section 2.7.1" ", " "IPC General Description".
  83. .IP " *" 4
  84. The data structure associated with each semaphore in the set need not
  85. be initialized. The
  86. \fIsemctl\fR()
  87. function with the command SETVAL or SETALL
  88. can be used to initialize each semaphore.
  89. .SH "RETURN VALUE"
  90. Upon successful completion,
  91. \fIsemget\fR()
  92. shall return a non-negative integer, namely a semaphore identifier;
  93. otherwise, it shall return \-1 and set
  94. .IR errno
  95. to indicate the error.
  96. .SH ERRORS
  97. The
  98. \fIsemget\fR()
  99. function shall fail if:
  100. .TP
  101. .BR EACCES
  102. A semaphore identifier exists for
  103. .IR key ,
  104. but operation permission as specified by the low-order 9 bits of
  105. .IR semflg
  106. would not be granted; see
  107. .IR "Section 2.7" ", " "XSI Interprocess Communication".
  108. .TP
  109. .BR EEXIST
  110. A semaphore identifier exists for the argument
  111. .IR key
  112. but ((\fIsemflg\fP &IPC_CREAT) &&(\fIsemflg\fP &IPC_EXCL))
  113. is non-zero.
  114. .TP
  115. .BR EINVAL
  116. The value of
  117. .IR nsems
  118. is either less than or equal to 0 or greater than the system-imposed
  119. limit, or a semaphore identifier exists for the argument
  120. .IR key ,
  121. but the number of semaphores in the set associated with it is less than
  122. .IR nsems
  123. and
  124. .IR nsems
  125. is not equal to 0.
  126. .TP
  127. .BR ENOENT
  128. A semaphore identifier does not exist for the argument
  129. .IR key
  130. and (\fIsemflg\fP &IPC_CREAT) is equal to 0.
  131. .TP
  132. .BR ENOSPC
  133. A semaphore identifier is to be created but the system-imposed limit on
  134. the maximum number of allowed semaphores system-wide would be
  135. exceeded.
  136. .LP
  137. .IR "The following sections are informative."
  138. .SH EXAMPLES
  139. Refer to
  140. .IR "\fIsemop\fR\^(\|)".
  141. .SH "APPLICATION USAGE"
  142. The POSIX Realtime Extension defines alternative interfaces for interprocess
  143. communication. Application developers who need to use IPC should
  144. design their applications so that modules using the IPC routines
  145. described in
  146. .IR "Section 2.7" ", " "XSI Interprocess Communication"
  147. can be easily modified to use the alternative interfaces.
  148. .SH RATIONALE
  149. None.
  150. .SH "FUTURE DIRECTIONS"
  151. A future version may require that the value of the
  152. .IR semval ,
  153. .IR sempid ,
  154. .IR semncnt ,
  155. and
  156. .IR semzcnt
  157. members of all semaphores in a semaphore set be initialized to zero when
  158. a call to
  159. \fIsemget\fR()
  160. creates a semaphore set. Many semaphore implementations already do this
  161. and it greatly simplifies what an application must do to initialize a
  162. semaphore set.
  163. .SH "SEE ALSO"
  164. .IR "Section 2.7" ", " "XSI Interprocess Communication",
  165. .IR "Section 2.8" ", " "Realtime",
  166. .IR "\fIftok\fR\^(\|)",
  167. .IR "\fIsemctl\fR\^(\|)",
  168. .IR "\fIsemop\fR\^(\|)",
  169. .IR "\fIsem_close\fR\^(\|)",
  170. .IR "\fIsem_destroy\fR\^(\|)",
  171. .IR "\fIsem_getvalue\fR\^(\|)",
  172. .IR "\fIsem_init\fR\^(\|)",
  173. .IR "\fIsem_open\fR\^(\|)",
  174. .IR "\fIsem_post\fR\^(\|)",
  175. .IR "\fIsem_trywait\fR\^(\|)",
  176. .IR "\fIsem_unlink\fR\^(\|)"
  177. .P
  178. The Base Definitions volume of POSIX.1\(hy2017,
  179. .IR "Section 4.17" ", " "Semaphore",
  180. .IR "\fB<sys_sem.h>\fP"
  181. .\"
  182. .SH COPYRIGHT
  183. Portions of this text are reprinted and reproduced in electronic form
  184. from IEEE Std 1003.1-2017, Standard for Information Technology
  185. -- Portable Operating System Interface (POSIX), The Open Group Base
  186. Specifications Issue 7, 2018 Edition,
  187. Copyright (C) 2018 by the Institute of
  188. Electrical and Electronics Engineers, Inc and The Open Group.
  189. In the event of any discrepancy between this version and the original IEEE and
  190. The Open Group Standard, the original IEEE and The Open Group Standard
  191. is the referee document. The original Standard can be obtained online at
  192. http://www.opengroup.org/unix/online.html .
  193. .PP
  194. Any typographical or formatting errors that appear
  195. in this page are most likely
  196. to have been introduced during the conversion of the source files to
  197. man page format. To report such errors, see
  198. https://www.kernel.org/doc/man-pages/reporting_bugs.html .