[Previous]
[Contents]
[Next]

qnx_psinfo()

return process information

Synopsis:

#include <sys/kernel.h>
#include <sys/psinfo.h>
#include <sys/seginfo.h>

pid_t qnx_psinfo( pid_t proc_pid,
                  pid_t pid,
                  struct _psinfo *psdata,
                  unsigned segindex,
                  struct _seginfo *segdata );

Description:

The qnx_psinfo() function returns information on a process pid from the process manager identified by proc_pid. If proc_pid is PROC_PID, then information on a process running on the current node is returned. If pid is zero, information on the calling process is returned.

The data is broken down into:


Note: The structures for psdata and segdata are quite large, so make sure the stack is large enough to hold them if they're placed there.

To obtain information on a process on another node, you must establish a virtual circuit to the process manager on that node and pass the vid as proc_pid. For example,

vid = qnx_vc_attach( node, PROC_PID, 1000, 0 );
status = qnx_psinfo( vid, pid, &psdata, 0, 0 );

Note: If you ask for information on a process that doesn't exist, information for another process might be returned. You should always check that the structure member psdata.pid contains the pid that was requested.

The _psinfo structure

The _psinfo structure contains information for virtual circuits (VCs), proxies, or processes, as well as information common to all. To determine which type (union member) to use, look at the flags field of the _psinfo structure:

    if (_psinfo.flags & _PPF_VID) {
        /* is a VC  -- use un.vproc */
    } else if (_psinfo.flags & _PPF_MID) {
        /* is a PROXY -- use un.mproc */
    } else {
        /* is a PROCESS -- use un.proc */
    }

The following fields from _psinfo are used no matter what type of information is returned:

pid
the process ID
blocked_on
if the state is SEND, RECV, REPLY, or SIGNAL, on whom it is waiting
pid_group
the process group
flags
See qnx_pflags().
rgid, ruid
the real group and user IDs
egid, euid
the effective group and user IDs
sp_reg, ss_reg
the stack pointer
magic_off, magic_sel
the address of _magic structure. See <sys/magic.h>
ldt
the Local Descriptor Table entry
umask
the file-creation mask
signal_ignore, signal_pending, signal_mask
the current signal bits
signal_off, signal_sel
the address of signal action table
state
the current execution state. See <sys/kernel.h>
priority
the current priority
max_priority
the maximum priority (SCHED_OTHER boost prio)
sched_algorithm
the current scheduling algorithm. See <sys/sched.h>
sid
the session ID
sid_nid
the node that owns this session

The following fields in the proc union member are used for processes:

father, son, brother
the family tree. Processes created by a common pid are linked as brothers.
debugger
If the process is currently being debugged, this is by whom.
mpass_pid, mpass_sel, mpass_flags
access rights from qnx_segment_arm(). Note that in later versions, you only require compatible user IDs to qnx_segment_get() and qnx_segment_put(). The arming is only needed between unique non-root user IDs.
name[100]
the name of the program image
links
the number of processes running this image
file_time
the file time of this image
nselectors
the number of selectors in this process
start_time
at what time the program started
struct tms times
user accounting information {utime,stime} for this and children.
mxcount
the number of bytes transferred last time this process received.
Note: The mxcount field is only 16 bits long.

The following fields in the vproc union member apply to virtual circuits:

local_pid
the process that owns this VC.
remote_pid
the process that's connected to this VC on the remote node.
remote_vid
the Virtual Circuit ID corresponding to this VC on the remote node.
remote_nid
which node the VC points to.
vidseg
the segment that contains the VC buffer.
links
the reference count for the VC.
substate
the internal state for VC. See <sys/kernel.h>

The following field in the mproc union member applies to proxies:

count
the number of counts against the proxy

The _seginfo structure

The _seginfo structure is defined with the qnx_segment_info() function. It contains at least the following members:

short unsigned selector
The memory segment.
short unsigned flags
The type of segment, using QNX's defined flags, not Intel's.
long addr
The physical linear memory address where the segment starts.
long nbytes
The size of the segment.

The parameter segdata must point to a buffer big enough to hold an array of 16 _seginfo structures. Memory on a process is maintained as a table of segments in the operating system. The segindex argument sets the starting point in the table to return information on.

int sindex;
struct _psinfo psdata;
struct _seginfo segdata[16];

for( sindex = 0;
    qnx_psinfo( PROC_PID, pid, &psdata, sindex, segdata )
      != -1;
    sindex += 16 )
    printf( "Number of selectors=%d\n",
        psdata.un.proc.nselectors );

Note: This function tries to guess how much "real" memory a segment uses, and adjusts nbytes accordingly. Use the qnx_segment_info() function to get the actual value.

Returns:

A process ID, or -1 if an error occurs. On error, errno is set.

Errors:

EINVAL
No process with a process ID >= pid exists.

Examples:

#include <stdio.h>
#include <sys/psinfo.h>

struct _psinfo data;

void main()
  {
    pid_t id;

    id = 1;
    while( ( id = qnx_psinfo( 0, id, &data, 0, 0 ) )
      != -1 ) {
      if( ( data.flags & ( _PPF_MID|_PPF_VID ) ) == 0 )
        printf( "%5d %s\n", id, data.un.proc.name );
      ++id;
    }
  }

Classification:

QNX

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

See also:

errno, qnx_osinfo(), qnx_segment_alloc(), qnx_segment_info(), qnx_vc_attach()


[Previous]
[Contents]
[Next]