MSGSND(2)
π MSGSND(2) β bestie edition
okay so this is msgsnd, a system call from the System Calls Manual bestie, and it lives in the Standard C Library (libc, -lc). it sends messages to message queues and honestly? iconic behavior.
β¨ NAME β¨
msgsnd β send a message to a message queue π¬
π LIBRARY π
Standard C Library (libc, -lc)
π SYNOPSIS π
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
int
msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
π DESCRIPTION π
so the way msgsnd() works is it sends a message to the message queue you specified in msqid. and msgp is a pointer to a structure holding the actual message. that structure should have these members, no cap:
long mtype; /* message type */
char mtext[1]; /* body of message */
mtype is an integer greater than 0 and it's what you use to pick out messages later (peep msgrcv(2) for that one π«Ά). and mtext is an array of msgsz bytes. the msgsz argument can go from 0 all the way up to a system-imposed maximum, MSGMAX. lowkey a glow-up range.
now here's the tea: if the number of bytes already chillin' on the message queue plus msgsz is bigger than the maximum number of bytes allowed on the queue (msg_qbytes, see msgctl(2)), or the number of messages on all queues system-wide is already equal to the system limit, then msgflg is the one deciding what msgsnd() does next:
- if
msgflghas theIPC_NOWAITmask set in it, the call just returns immediately. no waiting, main character energy. - if
msgflgdoes not haveIPC_NOWAITset in it, the call will block until:- the condition that made it block no longer exists. the message will be sent β¨
- the message queue is removed β in which case
-1gets returned anderrnois set toEINVALπ - the caller catches a signal. the call returns with
errnoset toEINTR.
after a successful call, the data structure associated with the message queue gets updated like this:
msg_cbytesis incremented by the size of the message.msg_qnumis incremented by1.msg_lspidis set to the pid of the calling process.msg_stimeis set to the current time.
π RETURN VALUES π
msgsnd() returns the value 0 if it slayed (successful π). otherwise the value -1 is returned and the global variable errno is set to indicate the error. sad girl hours fr.
π ERRORS π
msgsnd() will fail if:
[EINVAL]β themsqidargument is not a valid message queue identifier.
the message queue was removed while msgsnd() was waiting for a resource to become available in order to deliver the message.
the msgsz argument is greater than msg_qbytes.
the mtype argument is not greater than 0.
[EACCES]β the calling process does not have write access to the message queue. π[EAGAIN]β there was no space for this message either on the queue, or in the whole system, andIPC_NOWAITwas set inmsgflg.[EFAULT]β themsgpargument points to an invalid address.[EINTR]β the system call was interrupted by the delivery of a signal.
π¦ HISTORY π¦
message queues appeared in the first release of AT&T Unix System V. old money behavior honestly π
π BUGS π
NetBSD and FreeBSD do not define the EIDRM error value, which should be used in the case of a removed message queue. not them being inconsistent π
and that's the whole page bestie π this one shipped with Debian, dated July 9, 2009, and the man page is literally just called MSGSND(2). go send some messages, you got this π«Άβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1995 Frank van der Linden
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms