Copyright (C) 2000-2012 |
Manpages MSGOPSection: Linux Programmer's Manual (2)Updated: 2000-07-10 Index Return to Main Contents NAMEmsgop - message operationsSYNOPSIS# include <sys/types.h> int msgsnd ( int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg ) ssize_t msgrcv ( int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp, int msgflg ) DESCRIPTIONTo send or receive a message, the calling process allocates a structure that looks like the following
struct msgbuf {
but with an array The calling process must have write access permissions to send and read access permissions to receive a message on the queue. The msgsnd system call enqueues a copy of the message pointed to by the msgp argument on the message queue whose identifier is specified by the value of the msqid argument. The argument msgflg specifies the system call behaviour if enqueuing the new message will require more than msg_qbytes in the queue. Asserting IPC_NOWAIT the message will not be sent and the system call fails returning with errno set to EAGAIN. Otherwise the process is suspended until the condition for the suspension no longer exists (in which case the message is sent and the system call succeeds), or the queue is removed (in which case the system call fails with errno set to EIDRM), or the process receives a signal that has to be caught (in which case the system call fails with errno set to EINTR). Upon successful completion the message queue data structure is updated as follows:
The system call msgrcv reads a message from the message queue specified by msqid into the msgbuf pointed to by the msgp argument removing from the queue, on success, the read message. The argument msgsz specifies the maximum size in bytes for the member mtext of the structure pointed to by the msgp argument. If the message text has length greater than msgsz, then if the msgflg argument asserts MSG_NOERROR, the message text will be truncated (and the truncated part will be lost), otherwise the message isn't removed from the queue and the system call fails returning with errno set to E2BIG. The argument msgtyp specifies the type of message requested as follows:
The msgflg argument asserts none, one or more (or-ing them) among the following flags:
If no message of the requested type is available and IPC_NOWAIT isn't asserted in msgflg, the calling process is blocked until one of the following conditions occurs:
Upon successful completion the message queue data structure is updated as follows:
RETURN VALUEOn a failure both functions return -1 with errno indicating the error, otherwise msgsnd returns 0 and msgrvc returns the number of bytes actually copied into the mtext array.ERRORSWhen msgsnd fails, at return errno will be set to one among the following values:
When msgrcv fails, at return errno will be set to one among the following values:
NOTESThe followings are system limits affecting a msgsnd system call:
The implementation has no intrinsic limits for the system wide maximum number of message headers (MSGTQL) and for the system wide maximum size in bytes of the message pool (MSGPOOL). CONFORMING TOSVr4, SVID.NOTEThe pointer argument is declared as struct msgbuf * with libc4, libc5, glibc 2.0, glibc 2.1. It is declared as void * (const void * for msgsnd()) with glibc 2.2, following the SUSv2.SEE ALSOipc(5), msgctl(2), msgget(2), msgrcv(2), msgsnd(2)
IndexThis document was created by man2html, using the manual pages. Time: 02:14:36 GMT, January 21, 2025 |