check for a message from a process


#include <sys/kernel.h>
#include <sys/sendmx.h>
pid_t Creceivemx( pid_t pid, unsigned parts,
                  struct _mxfer_entry *msgmx );


The kernel function Creceivemx() checks to see if a message is waiting from the process identified by pid. If pid is nonzero, only messages from pid are received. If pid is zero, a message from any process or proxy is received. If a suitable message is waiting, it is received into the array of message buffers pointed to by msgmx. The number of elements in this array is given by nparts, which must not exceed _QNX_MXTAB_LEN (defined in <limits.h>). The size of the received message is limited to the total size of these buffers.

By default, messages sent to a process are queued in time order. This may be changed to priority order by using the qnx_pflags() function.

The number of bytes transferred is the minimum of that specified by both the sender and the receiver. The send data never overflows the buffer area provided by the receiver.

If a message is received, Creceivemx() changes the state of the sending task from SEND BLOCKED to REPLY BLOCKED.

This function's behavior is identical to that of Receivemx(), except it doesn't block if a message is not waiting. This function can be used to poll for messages. In general this is bad practice, and designs should attempt to avoid polling.

Note: Avoid stuffing each _mxfer_entry directly. Instead use the _setmx() macro to stuff each entry. This makes your code portable across 16- and 32-bit platforms.


The process ID of the process that sent the message. This ID is needed to reply to the message. If an error occurs, or no message is waiting, -1 is returned and errno is set.


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.
The call was interrupted by a signal.
No message is available.
The process pid doesn't exist.


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

int main( void )
    pid_t pid;
    short unsigned msg;
    struct _mxfer_entry mx[1];

    if( pid = fork() )
      Yield();         /* make sure the child runs first */
      Yield();         /* make sure the child runs first */
      Send( pid, &msg, &msg,
            sizeof( msg ), sizeof( msg ) );
      exit( 0 );

    _setmx( &mx[0], &msg, sizeof( msg ) );
    while( ( pid = Creceivemx( 0, 1, mx ) ) == -1 )
      printf( "No message.\n" );

    printf( "Message.\n" );
    Reply( pid, &msg, sizeof( msg ) );
    return( EXIT_SUCCESS );



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


Creceivemx() is a macro.

See also:

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