MSGSND(3P)
π MSGSND(3P) β bestie's guide to sending messages π
okay so real quick, this page lives in the POSIX Programmer's Manual β that's the msgsnd(3P) situation, manual name and all. π«Ά
πΈ PROLOG πΈ
so like, this manual page is part of the POSIX Programmer's Manual, bestie. that's its whole home. but heads up: the Linux implementation of this interface may differ β so if you're on Linux, go consult the corresponding Linux manual page for the deets on Linux behavior. OR, plot twist, the interface might just not be implemented on Linux at all. π vibe check accordingly.
β¨ NAME β¨
msgsnd β the XSI message send operation. that's it, that's the name, she's iconic π
π SYNOPSIS π
#include <sys/msg.h>
int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
π DESCRIPTION π
okay so msgsnd() operates on XSI message queues β see the Base Definitions volume of POSIX.1β2017, Section 3.226, Message Queue, iykyk. and ngl, it is unspecified whether this function interoperates with the realtime interprocess communication facilities defined in Section 2.8, Realtime. so like, don't assume, bestie.
msgsnd() shall send a message to the queue associated with the message queue identifier specified by msqid. slay, message delivered π¬
now, the application shall ensure that the argument msgp points to a user-defined buffer that contains first a field of type long specifying the type of the message, and then a data portion that holds the data bytes of the message. the structure below is an example of what this user-defined buffer might look like:
struct mymsg {
long mtype; /* Message type. */
char mtext[1]; /* Message text. */
}
the structure member mtype is a non-zero positive type long that can be used by the receiving process for message selection. non-zero. positive. don't forget π¨
the structure member mtext is any text of length msgsz bytes. and the argument msgsz can range from 0 to a system-imposed maximum.
the argument msgflg specifies the action to be taken if one or more of the following is true:
- the number of bytes already on the queue is equal to
msg_qbytes; see<sys/msg.h>. - the total number of messages on all queues system-wide is equal to the system-imposed limit.
and these actions are as follows, bestie:
- if
(msgflg & IPC_NOWAIT)is non-zero, the message shall not be sent and the calling thread shall return immediately. no waiting, we're busy π¨ - if
(msgflg & IPC_NOWAIT)is 0, the calling thread shall suspend execution until one of the following occurs:- the condition responsible for the suspension no longer exists, in which case the message is sent. yay, we love a happy ending π₯³
- the message queue identifier
msqidis removed from the system; when this occurs,errnoshall be set to[EIDRM]and-1shall be returned. rude honestly π - the calling thread receives a signal that is to be caught; in this case the message is not sent and the calling thread resumes execution in the manner prescribed in
sigaction().
upon successful completion, the following actions are taken with respect to the data structure associated with msqid; see <sys/msg.h>:
msg_qnumshall be incremented by 1.msg_lspidshall be set to the process ID of the calling process.msg_stimeshall be set to the current time, as described in Section 2.7.1, IPC General Description.
π RETURN VALUE π
upon successful completion, msgsnd() shall return 0. otherwise, no message shall be sent, msgsnd() shall return -1, and errno shall be set to indicate the error. simple as that π―
π₯ ERRORS π₯
the msgsnd() function shall fail if:
EACCESβ operation permission is denied to the calling process; see Section 2.7, XSI Interprocess Communication.EAGAINβ the message cannot be sent for one of the reasons cited above and(msgflg & IPC_NOWAIT)is non-zero.EIDRMβ the message queue identifiermsqidis removed from the system.EINTRβ themsgsnd()function was interrupted by a signal.EINVALβ the value ofmsqidis not a valid message queue identifier, or the value ofmtypeis less than 1; or the value ofmsgszis greater than the system-imposed limit.
the following sections are informative. (yes, fr fr, everything from here on is just tea and context β)
π¦ EXAMPLES π¦
Sending a Message
the following example sends a message to the queue identified by the msqid argument (assuming that value has previously been set). this call specifies that an error should be reported if no message is available. the message size is calculated directly using the sizeof operator. cute, efficient, iconic β¨
#include <sys/msg.h>
...
int result;
int msqid;
struct message {
long type;
char text[20];
} msg;
msg.type = 1;
strcpy(msg.text, "This is message 1");
...
result = msgsnd(msqid, (void *) &msg, sizeof(msg.text), IPC_NOWAIT);
π APPLICATION USAGE π
the POSIX Realtime Extension defines alternative interfaces for interprocess communication (IPC). application developers who need to use IPC should design their applications so that modules using the IPC routines described in Section 2.7, XSI Interprocess Communication can be easily modified to use the alternative interfaces. future-proofing, bestie, we love to see it π§
β RATIONALE β
None.
like. nothing. empty. the void. π
πΈ FUTURE DIRECTIONS πΈ
None.
again: nothing. we stay unbothered π
π SEE ALSO π
Section 2.7, XSI Interprocess Communication, Section 2.8, Realtime, mq_close(), mq_getattr(), mq_notify(), mq_open(), mq_receive(), mq_send(), mq_setattr(), mq_unlink(), msgctl(), msgget(), msgrcv(), sigaction()
the Base Definitions volume of POSIX.1β2017, Section 3.226, Message Queue, <sys_msg.h>
π COPYRIGHT π
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! this one came to you from IEEE/The Open Group, dated 2017, under the manual name MSGSND(3P) β so go send a message, respectfully, with your mtype non-zero and your vibes immaculate π«Άπ
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms