[Previous]
[Contents]
[Next]

qnx_name_attach()

register the process under a given name

Synopsis:

#include <sys/name.h>
int qnx_name_attach( nid_t nid, char *name );

Description:

The qnx_name_attach() function registers the calling process under the given name on the node specified by nid. If nid is zero, the name is registered on the local node.

Names may be up to 32 characters in length. If the first character is a slash (/), the name is considered global to the network. If the optional global process name server(s) are run, they build a database containing the nodes on which each slash name is located. The qnx_name_locate() function uses this server to locate these names.

You should attempt to prefix all your names with something like your company or product name. For example:

Name Type
acme/master local
acme/slave1 local
acme/slave2 local
/acme/nodemaster global

If the same global name is registered on two different nodes, then the global process name server(s) add both names to their databases. Since most applications expect a single name, this can result in confusion, so this practice should be avoided.

If you need to use a name as a network-wide semaphore, you can use the nid parameter to register these names on a single node. Names are unique on a node; an attempt to attach a name that already exists on that node fails. Note that this scheme represents a single point of failure, in that if that node goes down, all names are lost.

Returns:

A name_id if successful, otherwise -1, and errno is set. The name_id is to be used when calling the qnx_name_detach() function.

Errors:

EAGAIN
The name space is used up on that node.
EBUSY
The name already exists on that node.

Examples:

/* The server program. Run in background (prog &). */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/kernel.h>
#include <sys/name.h>

void main()
  {
    int id1, id2, msg;
    pid_t pid;

    id1 = qnx_name_attach( 0, "acme/test" );
    if( id1 == -1 ) {
      fprintf( stderr, "Attach1 failed.\n" );
      return;
    }

    id2 = qnx_name_attach( 0, "/acme/test" );
    if( id2 == -1 ) {
      fprintf( stderr, "Attach2 failed.\n" );
      return;
    }

    do {
      pid = Receive( 0, &msg, sizeof( msg ) );
      printf( "Received a message from %d.\n", pid );
      Reply( pid, &msg, sizeof( msg ) );
    } while( msg );

    qnx_name_detach( 0, id1 );
    qnx_name_detach( 0, id2 );

    exit( 0 );
  }

Classification:

QNX

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

See also:

errno, qnx_name_detach(), qnx_name_locate(), qnx_name_locators(), qnx_name_query()


[Previous]
[Contents]
[Next]