|
|
1.1 root 1: .TH MSGOP 2
2: .SH NAME
3: msgop \- message operations
4: .SH SYNOPSIS
5: .B #include <sys/types.h>
6: .br
7: .B #include <sys/ipc.h>
8: .br
9: .B #include <sys/msg.h>
10: .PP
11: .nf
12: .B int msgsnd (msqid, msgp, msgsz, msgflg)
13: .B int msqid;
14: .B struct msgbuf \(**msgp;
15: .B int msgsz, msgflg;
16: .PP
17: .B "int msgrcv (msqid, msgp, msgsz, msgtyp, msgflg)"
18: .B int msqid;
19: .B struct msgbuf \(**msgp;
20: .B int msgsz;
21: .B long msgtyp;
22: .B int msgflg;
23: .fi
24: .SH DESCRIPTION
25: Msgsnd is used to send a message to the queue associated with the message
26: queue identifier specified by
27: .IR msqid .
28: .SM {WRITE}
29: .I Msgp
30: points to a structure containing the message.
31: This structure is composed of the following members:
32: .PP
33: .RS
34: .ta 8n 20n
35: .nf
36: long mtype; /\(** message type \(**/
37: char mtext[]; /\(** message text \(**/
38: .fi
39: .RE
40: .PP
41: .I Mtype
42: is a positive integer that can be used by the receiving process for
43: message selection (see
44: .IR msgrcv " below").
45: .I Mtext
46: is any text of length
47: .I msgsz
48: bytes.
49: .I Msgsz
50: can range from 0 to a system-imposed maximum.
51: .PP
52: .I Msgflg
53: specifies the action to be taken if one or more of the following are true:
54: .IP
55: The number of bytes already on the queue is equal to
56: .BR msg_qbytes
57: .RI (see " intro" (2)).
58: .IP
59: The total number of messages on all queues system-wide is equal to the
60: system-imposed limit.
61: .PP
62: These actions are as follows:
63: .IP
64: If
65: .RI ( msgflg " & "
66: .SM
67: .BR IPC_NOWAIT\*S )
1.1.1.2 ! root 68: is ``true'', the message will not be sent and the calling process
! 69: returns immediately.
1.1 root 70: .IP
71: If
72: .RI ( msgflg " & "
73: .SM
74: .BR IPC_NOWAIT\*S )
75: is ``false'',
1.1.1.2 ! root 76: the calling process suspends execution until one of the following occurs:
1.1 root 77: .RS 8
78: .IP
79: The condition responsible for the suspension no longer exists, in which case
80: the message is sent.
81: .IP
82: .I Msqid
83: is removed from the system (see
84: .IR msgctl (2)).
85: When this occurs,
86: .I errno
87: is set equal to
88: .SM
89: \%EIDRM\*S,
90: and a value of \-1 is returned.
91: .IP
92: The calling process receives a signal that is to be caught.
93: In this case the message is not sent and the calling process resumes
94: execution in the manner prescribed in
95: .IR signal (2)).
96: .RE
97: .PP
98: .I Msgsnd
1.1.1.2 ! root 99: fails and no message is sent if one or more of the following are true:
1.1 root 100: .TP 15
101: .SM
102: \%[EINVAL]
103: .I Msqid
104: is not a valid message queue identifier.
105: .TP
106: .SM
107: \%[EACCES]
108: Operation permission is denied to the calling process (see
109: .IR intro (2)).
110: .TP
111: .SM
112: \%[EINVAL]
113: .I Mtype
114: is less than 1.
115: .TP
116: .SM
117: \%[EAGAIN]
118: The message cannot be sent for one of the reasons cited above and
119: .RI ( msgflg " & "
120: .SM
121: .BR IPC_NOWAIT\*S )
122: is ``true''.
123: .TP
124: .SM
125: \%[EINVAL]
126: .I Msgsz
127: is less than zero or greater than the system-imposed limit.
128: .TP
129: .SM
130: \%[EFAULT]
131: .I Msgp
132: points to an illegal address.
133: .PP
134: Upon successful completion, the following actions are taken with respect to
135: the data structure associated with
136: .IR msqid
137: (see intro (2)).
138: .IP
139: .B Msg_qnum
140: is incremented by 1.
141: .IP
142: .B Msg_lspid
143: is set equal to the process
144: .SM ID
145: of the calling process.
146: .IP
147: .B Msg_stime
148: is set equal to the current time.
149: .PP
150: .I Msgrcv
151: reads a message from the queue associated with the message queue identifier
152: specified by
153: .IR msqid
154: and places it in the structure pointed to by
155: .IR msgp .
156: .SM {READ}
157: This structure is composed of the following members:
158: .PP
159: .RS
160: .ta 8n 20n
161: .nf
162: long mtype; /\(** message type \(**/
163: char mtext[]; /\(** message text \(**/
164: .fi
165: .RE
166: .PP
167: .I Mtype
168: is the received message's type as specified by the sending process.
169: .I Mtext
170: is the text of the message.
171: .I Msgsz
172: specifies the size in bytes of
173: .IR mtext.
174: The received message is truncated to
175: .IR msgsz " bytes"
176: if it is larger than
177: .I msgsz
178: and
179: .RI ( msgflg " &"
180: .SM
181: .BR MSG_NOERROR\*S )
182: is ``true''.
183: The truncated part of the message is lost and no indication of the truncation is
184: given to the calling process.
185: .PP
186: .I Msgtyp
187: specifies the type of message requested as follows:
188: .IP
189: If
190: .I msgtyp
191: is equal to 0, the first message on the queue is received.
192: .IP
193: If
194: .I msgtyp
195: is greater than 0, the first message of type
196: .I msgtyp
197: is received.
198: .IP
199: If
200: .I msgtyp
201: is less than 0,
202: the first message of the lowest type that is less than or equal
203: to the absolute value of
204: .I msgtyp
205: is received.
206: .PP
207: .I Msgflg
208: specifies the action to be taken if a message of the desired type
209: is not on the queue.
210: These are as follows:
211: .IP
212: If
213: .RI ( msgflg " & "
214: .SM
215: .BR IPC_NOWAIT\*S )
1.1.1.2 ! root 216: is ``true'', the calling process returns immediately with a return value
1.1 root 217: of \-1 and
218: .I errno
219: set to
220: .SM
221: ENOMSG\*S.
222: .IP
223: If
224: .RI ( msgflg " & "
225: .SM
226: .BR IPC_NOWAIT\*S )
1.1.1.2 ! root 227: is ``false'', the calling process suspends execution until one of the
1.1 root 228: following occurs:
229: .RS 8
230: .IP
231: A message of the desired type is placed on the queue.
232: .IP
233: .I Msqid
234: is removed from the system.
235: When this occurs,
236: .I errno
237: is set equal to
238: .SM
239: \%EIDRM\*S,
240: and a value of \-1 is returned.
241: .IP
242: The calling process receives a signal that is to be caught.
243: In this case a message is not received and the calling process resumes
244: execution in the manner prescribed in
245: .IR signal (2)).
246: .RE
247: .PP
248: .I Msgrcv
1.1.1.2 ! root 249: fails and no message is received if one or more of the following are
1.1 root 250: true:
251: .TP 15
252: .SM
253: \%[EINVAL]
254: .I Msqid
255: is not a valid message queue identifier.
256: .TP
257: .SM
258: \%[EACCES]
259: Operation permission is denied to the calling process.
260: .TP
261: .SM
262: \%[EINVAL]
263: .I Msgsz
264: is less than 0.
265: .TP
266: .SM
267: \%[E2BIG]
268: Mtext is greater than
269: .I msgsz
270: and
271: .RI ( msgflg " &"
272: .SM
273: .BR MSG_NOERROR\*S )
274: is ``false''.
275: .TP
276: .SM
277: \%[ENOMSG]
278: The queue does not contain a message of the desired type and
279: .RI ( msgtyp " & "
280: .SM
281: .BR IPC_NOWAIT\*S )
282: is ``true''.
283: .TP
284: .SM
285: \%[EFAULT]
286: .I Msgp
287: points to an illegal address.
288: .PP
289: Upon successful completion, the following actions are taken with respect to
290: the data structure associated with
291: .IR msqid
292: (see intro (2)).
293: .IP
294: .B Msg_qnum
295: is decremented by 1.
296: .IP
297: .B Msg_lrpid
298: is set equal to the process
299: .SM ID
300: of the calling process.
301: .IP
302: .B Msg_rtime
303: is set equal to the current time.
304: .SH RETURN VALUES
305: .RI If " msgsnd " or " msgrcv"
306: return due to the receipt of a signal, a value of \-1 is returned to the
307: calling process and
308: .I errno
309: is set to
310: .SM
311: \%EINTR\*S.
312: If they return due to removal of
313: .I msqid
314: from the system, a value of \-1 is returned and
315: .I errno
316: is set to
317: .SM
318: \%EIDRM\*S.
319: .PP
320: Upon successful completion, the return value is as follows:
321: .IP
322: .I Msgsnd
323: returns a value of 0.
324: .IP
325: .I Msgrcv
326: returns a value equal to the number of bytes actually placed into
327: .IR mtext .
328: .PP
329: Otherwise, a value of \-1 is returned and
330: .I errno
331: is set to indicate the error.
332: .SH SEE ALSO
333: intro(2), msgctl(2), msgget(2), signal(2).
334: .\" @(#)msgop.2 6.2 of 9/6/83
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.