Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title How can my application display the kind of information displayed by the sin utility in QNX4?
Ref. No. QNX.000009319
Category(ies) Utilities, Development
Issue I'd like my application to display the kind of information displayed by the sin utility in QNX4. I could always parse the output of sin, but if sin changes down the road, my program will break. Is there a way to do this aside from using "sin"?




Solution An application can access this information by calling the qnx_psinfo() function. For example, the following program uses qnx_psinfo() to display all the process IDs (PIDs), along with their associated program names, for the local node. When the program encounters a virtual process ID (VID), it queries the remote end for the PID and name of the remote application.

#include <stdio.h>
#include <stdlib.h>
#include <sys/psinfo.h>
#include <sys/osinfo.h>
#include <sys/sys/vc.h>
#include <sys/kernel.h>

#define FALSE 0
#define TRUE 1

struct _psinfo data;
struct _osinfo osdata;

void
main(int argc, char *argv[])
{
x09int tmp, isvid;
x09pid_t nid, tnid, vid, svid, pid=1;

x09tnid=nid=atoi(argv[1]);

x09if(nid == 0){ /* Get logical node number of local node */
x09x09qnx_osinfo(0,&osdata);
x09x09tnid=nid=osdata.nodename;

x09}

x09/** Connect to PROC on node to be queried **/
x09if((vid=qnx_vc_attach(nid,PROC_PID,1000,0)) == -1)

x09{
x09x09printf("Unable to link to node %dn",nid);
x09x09exit(-1);
x09}

x09printf("Processes on node %d:n",nid);
x09/**
x09x09** Display processes on target node as well as
x09x09** all processes that have VCs to that node
x09x09**/
x09printf("Nodex09PIDx09Name nn");
x09while((pid=qnx_psinfo(vid,pid,&data,0,0))!= -1)
x09{
x09x09isvid=FALSE;
x09x09if((data.flags & _PPF_VID)!= 0)
x09x09{ /** If vid, find origin and get process into **/
x09x09isvid=TRUE;
x09x09if ((syid=qnx_vc_attach(data.un.vproc.remote_nid,PROC_PID,1000,0))== -1)
x09x09{
x09x09x09printf("Unable to talk to node %dn",data.un.vproc.remote_nid);
x09x09x09exit(-1);
x09x09}
x09x09tnid=nid; /** remember orig. node **/
x09x09nid=data.un.vproc.remote_nid;
x09x09if((tmp=qnx_psinfo(svid,data.un.vproc.remote_pid,&data,0,0))== -1)
x09x09{
x09x09x09printf("Unable to get into on process %dn"
x09x09x09x09,data.un.vproc.remote_pid);
x09x09x09exit(-1);
x09x09}
x09x09qnx_vc_detach(svid); /** Don't build up VCs! **/

x09}

x09x09if((data.flags & _PPF_MID) == 0)
x09x09x09prinf("%s %4d %5dx09%sn",isvid?"vc":" "
x09x09x09x09,nid,data.pid,data.un.proc.name);
x09x09nid=tnid;
x09x09pid++;
x09}

}

The qnx_psinfo() function can return other information as well, see the /usr/include/sys/psinfo.h header file for all the members of the psinfo structure.

Also, look at qnx_osinfo() as it provides similar information. What it returns for information is located in the /usr/include/sys/osinfo.h header file.