msgop.2

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 2 代码 · 共 347 行

2
347
字号
.\" SCCSID: @(#)msgop.2	2.5	8/24/87.TH msgop 2.SH Namemsgsnd, msgrcv \- message operations.SH Syntax#include <sys/types.h>.br#include <sys/ipc.h>.br#include <sys/msg.h>.PP.nfint msgsnd (\fImsqid, msgp, msgsz, msgflg\fP)int \fImsqid\fP;void *\fImsgp\fP;size_t \fImsgsz\fP;int \fImsgflg\fP;.PPint msgrcv (\fImsqid, msgp, msgsz, msgtyp, msgflg\fP)int \fImsqid\fP;void *\fImsgp\fP;size_t \fImsgsz\fP;long \fImsgtyp\fP;int \fImsgflg\fP;.fi.SH Description.NXB "msgop keyword".NXB "msgsnd system call".NXB "message" "operations".NXA "msgrcv system call" "msgctl system call".NXA "msgrcv system call" "msgget system call"There are two message operations system calls,.PN msgsndand.PN msgrcv ..SS msgsndThe.PN msgsndsystem callis used to send a message to the queue associated with the messagequeue identifier specified by.IR msqid .The.I msgpparameter points to a structure containing the message.This structure is composed of the following members:.EXlong	mtype;	/\(** message type \(**/char	mtext[];	/\(** message text \(**/.EEThe.I mtypeparameter is a positive integer that can be used by the receiving process formessage selection.  For more information, see the.PN msgrcvsection of this reference page.The.I mtextparameter is any text of length.I msgszbytes.The.I msgszparameter can range from 0 to a system-imposed maximum..PPThe.I msgflgparameter specifies the action to be takenif the number of bytes already on the queue is equal tomsg_qbytes.(For further information, see .MS intro 2 .) The parameter also specifies what happens when the total number of messages on all queues system-wide is equal to thesystem-imposed limit..PPIf either of these conditions is true, and if  (\fImsgflg\fR & IPC_NOWAIT)is true, the message is not sent and the calling process returns immediately.However, if either of the conditions is true and (\fImsgflg\fR & IPC_NOWAIT)is false,the calling process suspends execution untilone of the following occurs:.IP \(bu 5The condition responsible for the suspension no longerexists, in which case the message is sent..IP \(bu 5The.I msqidparameter is removed from the system.For further information, see .MS msgctl 2 .When this occurs,.I errnois set equal toEIDRM,and a value of \-1 is returned..IP \(bu 5The calling process receives a signal that is to be caught.In this case, the message is not sent and the calling process resumesexecution in the manner prescribed in.MS signal 3 ..PPThe.PN msgsndsystem call fails and no message is sent under the following conditions:.TP 15[EINVAL]The.I msqidparameter is not a valid message queue identifier..TP 15[EACCES]Operation permission is denied to the calling process.  For moreinformation, see .MS errno 2 ..TP 15[EINVAL]The.I mtypeparameter is less than 1..TP 15[EAGAIN]The message cannot be sent for one of the reasons cited above and(\fImsgflg\fP & IPC_NOWAIT)is true..TP 15[EINVAL]The.I msgszparameter is less than zero or greater than the system-imposed limit..TP 15[EFAULT]The.I msgpparameter points to an illegal address..PPUpon successful completion, the following actions are takenwith respect to the data structure associated with.IR msqid (for more information, see .MS errno 2 ):.IP \(bu 5The.I msg_qnumis incremented by 1..IP \(bu 5The.I msg_lspidis set equal to the process IDof the calling process..IP \(bu 5The.I msg_stimeis set equal to the current time..SS msgrcvThe.PN msgrcvsystem call reads a message from the queue associated with the message queueidentifier specified by.I msqid and places it in the structure pointed to by.IR msgp .This structure is composed of the following members:.PP.EXlong    mtype;      /\(** message type \(**/char    mtext[];    /\(** message text \(**/.EEThe.I mtypeparameter is the received message's type, as specified by the sending process.The.I mtextparameter is the text of the message.  The.I msgszparameter specifies the size, in bytes, of.IR mtext .The received message is truncated to.IR msgsz " bytes"if it is larger than.I msgszand(\fImsgflg\fP & MSG_NOERROR)is true.The truncated part of the message is lost and no indication ofthe truncation is given to the calling process..PPThe.I msgtypparameter specifies the type of message requested, as follows:.IP \(bu 5If.I msgtypis equal to 0, the first message on the queue is received..IP \(bu 5If.I msgtypis greater than 0, the first message of type.I msgtypis received..IP \(bu 5If.I msgtypis less than 0,the first message of the lowest type that is less than or equalto the absolute value of.I msgtypis received..PPThe.I msgflgparameter specifies the action to be taken if a message of the desired type is not on the queue.These specified actions are as follows:.IP \(bu 5If(\fImsgflg\fP & IPC_NOWAIT)is true, the calling process returns immediately with a valueof \-1 and.I errnoset toENOMSG..IP \(bu 5If (\fImsgflg\fP & IPC_NOWAIT)is false, the calling process suspends execution untilone of the following occurs:.RS.IP - 5A message of the desired type is placed on the queue..IP - 5The.I msqidparameter is removed from the system.When this occurs,.I errnois set equal toEIDRM,and a value of \-1 is returned..IP - 5The calling process receives a signal that is to be caught.In this case, a message is not received and the calling process resumesexecution in the manner prescribed in.MS signal 3 ..RE.PPThe.PN msgrcvsystem call fails and no message is received under the followingconditions:.TP 15[EINVAL]The.I msqidparameter is not a valid message queue identifier..TP[EACCES]Operation permission is denied to the calling process..TP[EINVAL]The.I msgszparameter is less than 0..TP[E2BIG]The.I mtext parameter is greater than.I msgszand(\fImsgflg\fP & MSG_NOERROR)is false..TP[ENOMSG]The queue does not contain a message of the desired type and(\fImsgtyp\fP & IPC_NOWAIT)is true..TP[EFAULT]The.I msgpparameter points to an illegal address..PPUpon successful completion,the following actions are taken with respect tothe data structure associated with.I msqid:  .IP \(bu 5The.I msg_qnumis decremented by 1..IP \(bu 5The.I msg_lrpidis set equal to the processIDof the calling process..IP \(bu 5The.I msg_rtimeis set equal to the current time..SH Return ValuesIf the.PN msgsndor.PN msgrcvsystem callsreturn due to the receipt of a signal, a value of \-1 isreturned to the calling process, anderrnois set toEINTR.If they return due to removal of.I msqidfrom the system, a value of \-1 is returned, anderrnois set toEIDRM..PPUpon successful completion, the return value is as follows:.IP \(bu 5The.PN msgsndsystem call returns a value of 0..IP \(bu 5The.PN msgrcvsystem callreturns a value equal to the number of bytes actually placed into.IR mtext ..PPOtherwise, a value of \-1 is returned, anderrnois set to indicate the error..SH See Alsoerrno(2), intro(2), msgctl(2), msgget(2), signal(3).NXE "msgop keyword".NXE "msgsnd system call".NXE "message" "operations"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?