[Previous]
[Contents]
[Next]

qnx_name_locate()

locate a process by its registered name

Synopsis:

#include <sys/name.h>
pid_t qnx_name_locate( nid_t nid,
                       char *name,
                       unsigned size,
                       unsigned *copies );

Description:

This function locates a process that has registered itself under the given name by calling qnx_name_attach().

The type of search made depends on the nid and name arguments passed to qnx_name_locate(), and on whether or not the global process name server, nameloc, is running:

Determining the type of search

  1. If nid isn't 0, the specific node is searched. No other search takes place, even if name starts with a slash (/).
  2. If nid is 0, the local node is searched. If name is found, no other search takes place, even if name starts with a slash.
  3. If the local search didn't succeed and name starts with a slash, the network is searched for the process.

Note: If nameloc isn't running somewhere on the network, the network-wide search can't be made.

If the located process exists remotely, qnx_name_locate() automatically attaches a virtual circuit (VC) to it. The size argument specifies the initial size of the virtual circuit buffer. This is typically the size of the largest message to be sent or returned. Since virtual circuits grow as needed, size can be zero.

If copies isn't NULL, it's set to the number of copies of the name found in the network. This can be used to detect more than one process with the same global name. For local and specific searches, the number of copies is always one, since a network search isn't involved.

Returns:

A process ID, or -1 if an error occurs; errno indicates the type of error detected.

Errors:

ESRCH
There's no process that has attached this name.

Examples:

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/kernel.h>
#include <sys/name.h>

int main ( void)
{

  pid_t proc_b;
  char send_msg[80], rcv_msg[80];

  proc_b = qnx_name_locate ( 0, "ProcessB", 0, NULL);
  
  if (proc_b == -1)
  {
    perror ("Couldn't find process B: ");
    return (EXIT_FAILURE);
  }
  else
  {
    printf ("Enter message to send to B: ");
    scanf ("%s", send_msg);

    if ( Send (proc_b, send_msg, rcv_msg, 80, 80) == -1)
    {
      perror ("Send to B failed:");
      exit (-1);
    }
  }

  return (EXIT_SUCCESS);
}

Classification:

QNX

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

See also:

errno, qnx_name_attach(), qnx_name_detach(), qnx_name_nodes(), qnx_name_query()

QNX System Architecture guide, nameloc in the QNX Utilities Reference


[Previous]
[Contents]
[Next]