1 .\" Copyright 1993 Giorgio Ciucci <giorgio@crcc.it>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Modified Tue Oct 22 16:40:11 1996 by Eric S. Raymond <esr@thyrsus.com>
24 .\" Modified Mon Jul 10 21:09:59 2000 by aeb
25 .\" Modified 1 Jun 2002, Michael Kerrisk <mtk-manpages@gmx.net>
26 .\" Language clean-ups.
27 .\" Enhanced and corrected information on msg_qbytes, MSGMNB and MSGMAX
28 .\" Added note on restart behavior of msgsnd() and msgrcv()
29 .\" Formatting clean-ups (argument and field names marked as .I
31 .\" Modified, 27 May 2004, Michael Kerrisk <mtk-manpages@gmx.net>
32 .\" Added notes on capability requirements
33 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk-manpages@gmx.net>
34 .\" Language and formatting clean-ups
35 .\" Added notes on /proc files
37 .TH MSGOP 2 2006-02-02 "Linux" "Linux Programmer's Manual"
39 msgop, msgrcv, msgsnd \- message operations
42 .B #include <sys/types.h>
43 .B #include <sys/ipc.h>
44 .B #include <sys/msg.h>
46 .BI "int msgsnd(int " msqid ", const void *" msgp ", size_t " msgsz \
49 .BI "ssize_t msgrcv(int " msqid ", void *" msgp ", size_t " msgsz \
58 system calls are used, respectively, to send messages to,
59 and receive messages from, a message queue.
60 The calling process must have write permission on the message queue
61 in order to send a message, and read permission to receive a message.
65 argument is a pointer to caller-defined structure
66 of the following general form:
71 long mtype; /* message type, must be > 0 */
72 char mtext[1]; /* message data */
79 field is an array (or other structure) whose size is specified by
81 a non-negative integer value.
82 Messages of zero length (i.e., no
87 field must have a strictly positive integer value.
89 used by the receiving process for message selection
90 (see the description of
96 system call appends a copy of the message pointed to by
98 to the message queue whose identifier is specified
102 If sufficient space is available in the queue,
104 succeeds immediately.
105 (The queue capacity is defined by the
107 field in the associated data structure for the message queue.
108 During queue creation this field is initialized to
110 bytes, but this limit can be modified using
112 If insufficient space is available in the queue, then the default
115 is to block until space becomes available.
120 then the call instead fails with the error
125 call may also fail if the queue is removed
126 (in which case the system call fails with
130 or a signal is caught (in which case the system call fails
135 .RB ( msgsnd " and " msgrcv
136 are never automatically restarted after being interrupted by a
137 signal handler, regardless of the setting of the
139 flag when establishing a signal handler.)
141 Upon successful completion the message queue data structure is updated
145 is set to the process ID of the calling process.
151 is set to the current time.
155 removes a message from the queue specified by
157 and places it in the buffer
163 specifies the maximum size in bytes for the member
165 of the structure pointed to by the
168 If the message text has length greater than
170 then the behavior depends on whether
177 the message text will be truncated (and the truncated part will be
180 is not specified, then
181 the message isn't removed from the queue and
182 the system call fails returning \-1 with
189 specifies the type of message requested as follows:
194 then the first message in the queue is read.
199 then the first message in the queue of type
206 the first message in the queue of type not equal to
213 then the first message in the queue with the lowest type less than or
214 equal to the absolute value of
220 argument is a bit mask constructed by ORing together zero or more
221 of the following flags:
224 Return immediately if no message of the requested type is in the queue.
225 The system call fails with
234 to read the first message in the queue with message type that differs
239 To truncate the message text if longer than
243 If no message of the requested type is available and
247 the calling process is blocked until one of the following conditions occurs:
249 A message of the desired type is placed in the queue.
251 The message queue is removed from the system.
252 In this case the system call fails with
257 The calling process catches a signal.
258 In this case the system call fails with
263 Upon successful completion the message queue data structure is updated
267 is set to the process ID of the calling process.
273 is set to the current time.
275 On failure both functions return \-1
278 indicating the error,
284 returns the number of bytes actually copied into the
292 will be set to one among the following values:
295 The calling process does not have write permission on the message queue,
296 and does not have the
301 The message can't be sent due to the
303 limit for the queue and
309 The address pointed to by
314 The message queue was removed.
317 Sleeping on a full message queue condition, the process caught a signal.
322 value, or non-positive
327 value (less than 0 or greater than the system value
331 The system does not have enough memory to make a copy of the
332 message pointed to by
339 will be set to one among the following values:
342 The message text length is greater than
350 The calling process does not have read permission on the message queue,
351 and does not have the
356 No message was available in the queue and
362 The address pointed to by
367 While the process was sleeping to receive a message,
368 the message queue was removed.
371 While the process was sleeping to receive a message,
372 the process caught a signal.
384 and no message of the requested type existed on the message queue.
390 argument is declared as \fIstruct msgbuf *\fP with
391 libc4, libc5, glibc 2.0, glibc 2.1.
392 It is declared as \fIvoid *\fP
393 with glibc 2.2 and later, as required by SUSv2 and SUSv3.
395 The following limits on message queue resources affect the
400 Maximum size for a message text: 8192 bytes
401 (on Linux, this limit can be read and modified via
402 .IR /proc/sys/kernel/msgmax ).
405 Default maximum size in bytes of a message queue: 16384 bytes
406 (on Linux, this limit can be read and modified via
407 .IR /proc/sys/kernel/msgmnb ).
408 The superuser can increase the size of a message queue beyond
414 The implementation has no intrinsic limits for the system wide maximum
415 number of message headers
417 and for the system wide maximum size in bytes of the message pool
424 .BR capabilities (7),