1 .\" Copyright 1993 Giorgio Ciucci <giorgio@crcc.it>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Modified Tue Oct 22 16:40:11 1996 by Eric S. Raymond <esr@thyrsus.com>
26 .\" Modified Mon Jul 10 21:09:59 2000 by aeb
27 .\" Modified 1 Jun 2002, Michael Kerrisk <mtk.manpages@gmail.com>
28 .\" Language clean-ups.
29 .\" Enhanced and corrected information on msg_qbytes, MSGMNB and MSGMAX
30 .\" Added note on restart behavior of msgsnd() and msgrcv()
31 .\" Formatting clean-ups (argument and field names marked as .I
33 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
34 .\" Added notes on capability requirements
35 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
36 .\" Language and formatting clean-ups
37 .\" Added notes on /proc files
38 .\" FIXME . Add example programs to this page.
40 .TH MSGOP 2 2014-03-17 "Linux" "Linux Programmer's Manual"
42 msgrcv, msgsnd \- System V message queue operations
45 .B #include <sys/types.h>
46 .B #include <sys/ipc.h>
47 .B #include <sys/msg.h>
49 .BI "int msgsnd(int " msqid ", const void *" msgp ", size_t " msgsz \
52 .BI "ssize_t msgrcv(int " msqid ", void *" msgp ", size_t " msgsz \
61 system calls are used, respectively, to send messages to,
62 and receive messages from, a System V message queue.
63 The calling process must have write permission on the message queue
64 in order to send a message, and read permission to receive a message.
68 argument is a pointer to a caller-defined structure
69 of the following general form:
74 long mtype; /* message type, must be > 0 */
75 char mtext[1]; /* message data */
82 field is an array (or other structure) whose size is specified by
84 a nonnegative integer value.
85 Messages of zero length (i.e., no
90 field must have a strictly positive integer value.
92 used by the receiving process for message selection
93 (see the description of
99 system call appends a copy of the message pointed to by
101 to the message queue whose identifier is specified
105 If sufficient space is available in the queue,
107 succeeds immediately.
108 (The queue capacity is defined by the
110 field in the associated data structure for the message queue.
111 During queue creation this field is initialized to
113 bytes, but this limit can be modified using
115 If insufficient space is available in the queue, then the default
118 is to block until space becomes available.
123 then the call instead fails with the error
128 call may also fail if:
130 the queue is removed,
131 in which case the system call fails with
137 a signal is caught, in which case the system call fails
144 is never automatically restarted after being interrupted by a
145 signal handler, regardless of the setting of the
147 flag when establishing a signal handler.)
149 Upon successful completion the message queue data structure is updated
153 is set to the process ID of the calling process.
159 is set to the current time.
163 system call removes a message from the queue specified by
165 and places it in the buffer
171 specifies the maximum size in bytes for the member
173 of the structure pointed to by the
176 If the message text has length greater than
178 then the behavior depends on whether
185 the message text will be truncated (and the truncated part will be
188 is not specified, then
189 the message isn't removed from the queue and
190 the system call fails returning \-1 with
202 argument specifies the type of message requested, as follows:
207 then the first message in the queue is read.
212 then the first message in the queue of type
219 the first message in the queue of type not equal to
226 then the first message in the queue with the lowest type less than or
227 equal to the absolute value of
233 argument is a bit mask constructed by ORing together zero or more
234 of the following flags:
237 Return immediately if no message of the requested type is in the queue.
238 The system call fails with
243 .BR MSG_COPY " (since Linux 3.8)"
244 .\" commit 4a674f34ba04a002244edaf891b5da7fc1473ae8
245 Nondestructively fetch a copy of the message at the ordinal position
246 in the queue specified by
248 (messages are considered to be numbered starting at 0).
250 This flag must be specified in conjunction with
252 with the result that, if there is no message available at the given position,
253 the call fails immediately with the error
255 Because they alter the meaning of
261 may not both be specified in
266 flag was added for the implementation of
267 the kernel checkpoint-restore facility and
268 is available only if the kernel was built with the
269 .B CONFIG_CHECKPOINT_RESTORE
276 to read the first message in the queue with message type that differs
281 To truncate the message text if longer than
285 If no message of the requested type is available and
289 the calling process is blocked until one of the following conditions occurs:
291 A message of the desired type is placed in the queue.
293 The message queue is removed from the system.
294 In this case, the system call fails with
299 The calling process catches a signal.
300 In this case, the system call fails with
305 is never automatically restarted after being interrupted by a
306 signal handler, regardless of the setting of the
308 flag when establishing a signal handler.)
310 Upon successful completion the message queue data structure is updated
314 is set to the process ID of the calling process.
320 is set to the current time.
322 On failure both functions return \-1
325 indicating the error,
331 returns the number of bytes actually copied into the
339 will be set to one among the following values:
342 The calling process does not have write permission on the message queue,
343 and does not have the
348 The message can't be sent due to the
350 limit for the queue and
356 The address pointed to by
361 The message queue was removed.
364 Sleeping on a full message queue condition, the process caught a signal.
369 value, or nonpositive
374 value (less than 0 or greater than the system value
378 The system does not have enough memory to make a copy of the
379 message pointed to by
386 will be set to one among the following values:
389 The message text length is greater than
397 The calling process does not have read permission on the message queue,
398 and does not have the
403 No message was available in the queue and
409 The address pointed to by
414 While the process was sleeping to receive a message,
415 the message queue was removed.
418 While the process was sleeping to receive a message,
419 the process caught a signal; see
428 .BR EINVAL " (since Linux 3.14)"
435 .BR EINVAL " (since Linux 3.14)"
446 and no message of the requested type existed on the message queue.
454 and the queue contains less than
458 .BR ENOSYS " (since Linux 3.8)"
462 and this kernel was configured without
463 .BR CONFIG_CHECKPOINT_RESTORE .
471 flags are Linux-specific;
472 their definitions can be obtained by defining the
474 .\" MSG_COPY since glibc 2.18
481 isn't required on Linux or by any version of POSIX.
483 some old implementations required the inclusion of these header files,
484 and the SVID also documented their inclusion.
485 Applications intended to be portable to such old systems may need
486 to include these header files.
487 .\" Like Linux, the FreeBSD man pages still document
488 .\" the inclusion of these header files.
492 argument is declared as \fIstruct msgbuf *\fP with
493 libc4, libc5, glibc 2.0, glibc 2.1.
494 It is declared as \fIvoid *\fP
495 with glibc 2.2 and later, as required by SUSv2 and SUSv3.
497 The following limits on message queue resources affect the
502 Maximum size for a message text: 8192 bytes
503 (on Linux, this limit can be read and modified via
504 .IR /proc/sys/kernel/msgmax ).
507 Default maximum size in bytes of a message queue: 16384 bytes
508 (on Linux, this limit can be read and modified via
509 .IR /proc/sys/kernel/msgmnb ).
510 The superuser can increase the size of a message queue beyond
516 The implementation has no intrinsic limits for the system wide maximum
517 number of message headers
519 and for the system wide maximum size in bytes of the message pool
522 In Linux 3.13 and earlier,
529 and the message queue contained less than
531 messages, then the call would block until the next message is written
533 .\" FIXME http://marc.info/?l=linux-kernel&m=139048542803605&w=2
534 At that point, the call would return a copy of the message,
536 of whether that message was at the ordinal position
539 .\" commit 4f87dac386cc43d5525da7a939d4b4e7edbea22c
548 is a logical error (since these flags impose different interpretations on
550 In Linux 3.13 and earlier,
551 .\" FIXME http://marc.info/?l=linux-kernel&m=139048542803605&w=2
552 this error was not diagnosed by
555 .\" commit 4f87dac386cc43d5525da7a939d4b4e7edbea22c
560 .BR capabilities (7),
564 This page is part of release 3.64 of the Linux
567 A description of the project,
568 and information about reporting bugs,
570 \%http://www.kernel.org/doc/man\-pages/.