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 msqid is removed from the system; when this occurs, errno shall be set to [EIDRM] and -1 shall 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_qnum shall be incremented by 1.
  • msg_lspid shall be set to the process ID of the calling process.
  • msg_stime shall 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 identifier msqid is removed from the system.
  • EINTR β€” the msgsnd() function was interrupted by a signal.
  • EINVAL β€” the value of msqid is not a valid message queue identifier, or the value of mtype is less than 1; or the value of msgsz is 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>


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