relay a message from one process to another


#include <sys/types.h>
#include <sys/kernel.h>
int Relay( pid_t source, pid_t target );


The Relay() function takes the message received from the source process, and relays it to the target process. The target process then receives the message as if it had originally been sent to it by the source process. The Relay() function doesn't block.

Note: The source and target processes must be on the same node as the process that called Relay(). The Relay() function doesn't work over the network. For this reason, it's good practice to design your applications to reply with a message status, giving the node and process ID of a new process for the sender to send to. It can then set up a new virtual circuit, if required.


An error occurred. errno is set to indicate the error.


Either the source or target doesn't exist, or they aren't reply-blocked.


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

unsigned msg[1];

 * This is one tricky example. Three processes are
 * involved.  A sends to B which relays to C which
 * replies back to A.
void main()
    pid_t child1, child2, pid;

    if( child1 = fork() )
      if( child2 = fork() ) {
    /* A */
    printf( "%d: Send to %d.\n", getpid(), child2 );
    Send( child2, msg, msg,
            sizeof( msg ), sizeof( msg ) );
      } else {
    /* B */
    pid = Receive( 0, msg, sizeof( msg ) );
    Relay( pid, child1 );
    printf( "%d: Receive from %d and Relay to %d.\n",
           getpid(), pid, child1 );
    else {
      /* C */
      pid = Receive( 0, msg, sizeof( msg ) );
      Reply( pid, msg, sizeof( msg ) );
      printf( "%d: Receive from %d and Reply to %d.\n",
         getpid(), pid, pid );

    exit( 0 );



Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes


Relay() is a macro.

See also:

Receive(), Reply(), Send()