msgget.2 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. .\" $NetBSD: msgget.2,v 1.1 1995/10/16 23:49:19 jtc Exp $
  2. .\"
  3. .\" Copyright (c) 1995 Frank van der Linden
  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. .\" 3. All advertising materials mentioning features or use of this software
  15. .\" must display the following acknowledgement:
  16. .\" This product includes software developed for the NetBSD Project
  17. .\" by Frank van der Linden
  18. .\" 4. The name of the author may not be used to endorse or promote products
  19. .\" derived from this software without specific prior written permission
  20. .\"
  21. .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  22. .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  23. .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. .\"
  32. .\"/
  33. .Dd March 4, 2018
  34. .Dt MSGGET 2
  35. .Os
  36. .Sh NAME
  37. .Nm msgget
  38. .Nd get message queue
  39. .Sh LIBRARY
  40. .Lb libc
  41. .Sh SYNOPSIS
  42. .In sys/msg.h
  43. .Ft int
  44. .Fn msgget "key_t key" "int msgflg"
  45. .Sh DESCRIPTION
  46. The
  47. .Fn msgget
  48. function
  49. returns the message queue identifier associated with
  50. .Fa key .
  51. A message queue identifier is a unique integer greater than zero.
  52. .Pp
  53. A message queue is created if either
  54. .Fa key
  55. is equal to
  56. .Dv IPC_PRIVATE ,
  57. or
  58. .Fa key
  59. does not have a message queue identifier associated with it, and the
  60. .Dv IPC_CREAT
  61. bit is set in
  62. .Fa msgflg .
  63. .Pp
  64. If a new message queue is created, the data structure associated with it (the
  65. .Va msqid_ds
  66. structure, see
  67. .Xr msgctl 2 )
  68. is initialized as follows:
  69. .Bl -bullet
  70. .It
  71. .Va msg_perm.cuid
  72. and
  73. .Va msg_perm.uid
  74. are set to the effective uid of the calling process.
  75. .It
  76. .Va msg_perm.gid
  77. and
  78. .Va msg_perm.cgid
  79. are set to the effective gid of the calling process.
  80. .It
  81. .Va msg_perm.mode
  82. is set to the lower 9 bits of
  83. .Fa msgflg
  84. which are set by ORing these constants:
  85. .Bl -tag -width 0000
  86. .It Dv 0400
  87. Read access for user.
  88. .It Dv 0200
  89. Write access for user.
  90. .It Dv 0040
  91. Read access for group.
  92. .It Dv 0020
  93. Write access for group.
  94. .It Dv 0004
  95. Read access for other.
  96. .It Dv 0002
  97. Write access for other.
  98. .El
  99. .It
  100. .Va msg_cbytes ,
  101. .Va msg_qnum ,
  102. .Va msg_lspid ,
  103. .Va msg_lrpid ,
  104. .Va msg_rtime ,
  105. and
  106. .Va msg_stime
  107. are set to 0.
  108. .It
  109. .Va msg_qbytes
  110. is set to the system wide maximum value for the number of bytes in a queue
  111. .Pf ( Dv MSGMNB ) .
  112. .It
  113. .Va msg_ctime
  114. is set to the current time.
  115. .El
  116. .Sh RETURN VALUES
  117. Upon successful completion a positive message queue identifier is returned.
  118. Otherwise, -1 is returned and the global variable
  119. .Va errno
  120. is set to indicate the error.
  121. .Sh ERRORS
  122. .Bl -tag -width Er
  123. .It Bq Er EACCES
  124. A message queue is already associated with
  125. .Fa key
  126. and the caller has no permission to access it.
  127. .It Bq Er EEXIST
  128. Both
  129. .Dv IPC_CREAT
  130. and
  131. .Dv IPC_EXCL
  132. are set in
  133. .Fa msgflg ,
  134. and a message queue is already associated with
  135. .Fa key .
  136. .It Bq Er ENOSPC
  137. A new message queue could not be created because the system limit for
  138. the number of message queues has been reached.
  139. .It Bq Er ENOENT
  140. .Dv IPC_CREAT
  141. was not set in
  142. .Fa msgflg
  143. and no message queue associated with
  144. .Fa key
  145. was found.
  146. .El
  147. .Sh SEE ALSO
  148. .Xr msgctl 2 ,
  149. .Xr msgrcv 2 ,
  150. .Xr msgsnd 2
  151. .Sh HISTORY
  152. Message queues appeared in the first release of
  153. .At V .