write data to a reply message buffer


#include <sys/kernel.h>
unsigned Writemsg( pid_t pid,
                   unsigned offset,
                   void *msg,
                   unsigned nbytes );


The kernel function Writemsg() writes nbytes of data from the buffer pointed to by msg to the reply message buffer of the process identified by pid. The offset allows you to write data to the sender's reply message buffer starting at any point. The data transfer occurs immediately, and your process doesn't block. The state of the process pid isn't changed. You must call Reply() or Replymx() to READY the sender and complete the message exchange.

The process pid must have sent a message that was received and not yet replied to. It must be in the REPLY BLOCKED state.

If you attempt to write past the end of the sender's reply buffer then Writemsg() returns fewer bytes than was specified by nbytes.

Writemsg() is a simple cover function that builds a single part _mxfer_entry on the stack and calls Writemsgmx(), which is the real kernel function. It's provided for convenience since it's easier to use than Writemsgmx() for simple messages. Please read the documentation for Writemsgmx() for examples on when to use it.


The number of bytes written. On error, -1 is returned, and errno is set.


No more Process Manager to Network Manager queue packets available.
In order to complete the message exchange, the current process would have incurred a segment violation. You need to make your buffer(s) larger, or limit the number of bytes allowed in the transfer.
Call interrupted by a signal.
The virtual circuit buffer can't be grown due to an invalid message length.
The virtual circuit buffer can't be grown because no memory is available.
The process pid doesn't exist.


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/kernel.h>

unsigned msg[2];

void main()
    pid_t child, pid;

    if( child = fork() )
      Send( child, msg, msg, sizeof( msg ),
        sizeof( msg ) );
      printf( "Send returned %d %d.\n", msg[0], msg[1] );
      pid = Receive( 0, msg, sizeof( msg ) );
      msg[1] = 2;
      Writemsg( pid, sizeof( msg[0] ), &msg[1],
           sizeof( msg[1] ) );
      msg[0] = 1;
      Reply( pid, msg, sizeof( msg[0] ) );

    exit( 0 );

produces the output:

Send returned 1 2.



Interrupt handler No
Signal handler Yes
Thread Yes


Writemsg() is a macro.

See also:

Creceive(), Creceivemx(), errno, Receive(), Receivemx(), Reply(), Replymx(), Readmsg(), Readmsgmx(), Send(), Sendfd(), Sendfdmx(), Sendmx(), Trigger(), Writemsgmx()