_psinfo

I need to find a process argument list in code. I can’t seem to locate it in
the _psinfo structure. Does anyone know how “sin ar” works?

Phil Wilson <wilson@cwnet.com> wrote:

I need to find a process argument list in code. I can’t seem to locate it in
the _psinfo structure. Does anyone know how “sin ar” works?

Task sin args use function __qnx_debug_xfer (sys/debug.h).
Here is small example, how you can to gain process arguments of process Pid.

First you should read psinfo of process, next counting position of cmd item and read this item.
Second to read struct _proc_spawn, and extract arguments from this structure.

pid_t Pid = 1;
nid_t Nid = 0;
struct _psinfo PsInfo;
struct _proc_spawn *ProcSpawn;
union _debug_data Data;
unsigned MagicSel;
unsigned long MagicOff;
void *VoidPtr;
char *p;
int i;

if( (Pid = qnx_psinfo( Nid, Pid, &PsInfo, 0, 0 )) != -1 )
{
// Test for valid process
if( PsInfo.flags & ( _PPF_VID | _PPF_MID ) )
return;

// Count position of cmd in struct _magic
MagicOff = PsInfo.magic_off + offsetof( struct _magic, cmd );
MagicSel = PsInfo.magic_sel;

// Read item cmd from process Pid
if( __qnx_debug_xfer( Nid, Pid, _DEBUG_MEM_RD, &VoidPtr, sizeof( void * ), MagicOff, MagicSel ) != -1 )
{
// read struct _proc_spawn from address VoidPtr
if( __qnx_debug_xfer( Nid, Pid, _DEBUG_MEM_RD, &Data, sizeof( union debug_data ), ( unsigned long ) VoidPtr, MagicSel ) != -1 )
{ ProcSpawn = ( struct _proc_spawn * ) &Data;
p = ProcSpawn->data;

// Access to arguments
for( i=0; i < ProcSpawn->argc; i++ )
{ printf(“Arg%i is %s”, i, p );

// Warning ProcSpan->data can by up to 64K. I read only 512B. I don’t know how many bytes
// function __qnx_debug_xfer can to transfer.
p += strlen( p ) + 1;

}
}
}
}


Good luck
Majo.

Thanks, however the call to __qnx_debug_xfer always returns -1…
I am new to this news group but not to QNX. But I have no information about
the debug functions. Anyone out there with this documentation?
BTW, I noticed that about a year ago someone else asked this very same
question. He was told to try popen(“sin ar”) . I suppose this would work,
but I prefer the Magic memory solution…

Any comments?

“Marian Oklapek” <majo@microstep-mis.sk> wrote in message
news:agc4vg$a0q$1@charon.microstep-mis.sk

Phil Wilson <> wilson@cwnet.com> > wrote:
I need to find a process argument list in code. I can’t seem to locate
it in
the _psinfo structure. Does anyone know how “sin ar” works?

Task sin args use function __qnx_debug_xfer (sys/debug.h).
Here is small example, how you can to gain process arguments of process
Pid.

First you should read psinfo of process, next counting position of cmd
item and read this item.
Second to read struct _proc_spawn, and extract arguments from this
structure.

pid_t Pid = 1;
nid_t Nid = 0;
struct _psinfo PsInfo;
struct _proc_spawn *ProcSpawn;
union _debug_data Data;
unsigned MagicSel;
unsigned long MagicOff;
void *VoidPtr;
char *p;
int i;

if( (Pid = qnx_psinfo( Nid, Pid, &PsInfo, 0, 0 )) != -1 )
{
// Test for valid process
if( PsInfo.flags & ( _PPF_VID | _PPF_MID ) )
return;

// Count position of cmd in struct _magic
MagicOff = PsInfo.magic_off + offsetof( struct _magic, cmd );
MagicSel = PsInfo.magic_sel;

// Read item cmd from process Pid
if( __qnx_debug_xfer( Nid, Pid, _DEBUG_MEM_RD, &VoidPtr, sizeof( void

  • ), MagicOff, MagicSel ) != -1 )
    {
    // read struct _proc_spawn from address VoidPtr
    if( __qnx_debug_xfer( Nid, Pid, _DEBUG_MEM_RD, &Data, sizeof( union
    debug_data ), ( unsigned long ) VoidPtr, MagicSel ) != -1 )
    { ProcSpawn = ( struct _proc_spawn * ) &Data;
    p = ProcSpawn->data;

// Access to arguments
for( i=0; i < ProcSpawn->argc; i++ )
{ printf(“Arg%i is %s”, i, p );

// Warning ProcSpan->data can by up to 64K. I read only 512B. I don’t know
how many bytes
// function __qnx_debug_xfer can to transfer.
p += strlen( p ) + 1;

}
}
}
}


Good luck
Majo.

I’m sorry, I made mistake when I transcribed example.( I have no information about debug functions too ).
This exampe don’t work. The function __qnx_debug_xfer don’t work when value Nid is 0 .
The Value Nid should be set as network ID Nid = getnid(), or virtual circuit ID if you
want work with another node e.g. pid_t Nid = qnx_vc_attach( 21, PROC_PID, 0, 0 )

Majo.

Phil Wilson <wilson@cwnet.com> wrote:

Thanks, however the call to __qnx_debug_xfer always returns -1…
I am new to this news group but not to QNX. But I have no information about
the debug functions. Anyone out there with this documentation?
BTW, I noticed that about a year ago someone else asked this very same
question. He was told to try popen(“sin ar”) . I suppose this would work,
but I prefer the Magic memory solution…

Any comments?

“Marian Oklapek” <> majo@microstep-mis.sk> > wrote in message
news:agc4vg$a0q$> 1@charon.microstep-mis.sk> …
Phil Wilson <> wilson@cwnet.com> > wrote:
I need to find a process argument list in code. I can’t seem to locate
it in
the _psinfo structure. Does anyone know how “sin ar” works?

Task sin args use function __qnx_debug_xfer (sys/debug.h).
Here is small example, how you can to gain process arguments of process
Pid.

First you should read psinfo of process, next counting position of cmd
item and read this item.
Second to read struct _proc_spawn, and extract arguments from this
structure.

pid_t Pid = 1;
nid_t Nid = 0;
!! nid_t Nid = getnid();



struct _psinfo PsInfo;
struct _proc_spawn *ProcSpawn;
union _debug_data Data;
unsigned MagicSel;
unsigned long MagicOff;
void *VoidPtr;
char *p;
int i;

if( (Pid = qnx_psinfo( Nid, Pid, &PsInfo, 0, 0 )) != -1 )
{
// Test for valid process
if( PsInfo.flags & ( _PPF_VID | _PPF_MID ) )
return;

// Count position of cmd in struct _magic
MagicOff = PsInfo.magic_off + offsetof( struct _magic, cmd );
MagicSel = PsInfo.magic_sel;

// Read item cmd from process Pid
if( __qnx_debug_xfer( Nid, Pid, _DEBUG_MEM_RD, &VoidPtr, sizeof( void

  • ), MagicOff, MagicSel ) != -1 )
    {
    // read struct _proc_spawn from address VoidPtr
    if( __qnx_debug_xfer( Nid, Pid, _DEBUG_MEM_RD, &Data, sizeof( union
    debug_data ), ( unsigned long ) VoidPtr, MagicSel ) != -1 )
    { ProcSpawn = ( struct _proc_spawn * ) &Data;
    p = ProcSpawn->data;

// Access to arguments
for( i=0; i < ProcSpawn->argc; i++ )
{ printf(“Arg%i is %s”, i, p );

// Warning ProcSpan->data can by up to 64K. I read only 512B. I don’t know
how many bytes
// function __qnx_debug_xfer can to transfer.
p += strlen( p ) + 1;

}
}
}
}


Good luck
Majo.

This doesn’t work either. __qnx_debug_xfer() still returns -1 but the
errno has now changed to 89 (Unknown System Call).

It’s a pity there is no documentation of the debug functions. Sort of
like that lack of docs for QNX4 resource managers… and special double
underscore functions required there…

Geoff.


Marian Oklapek wrote:

I’m sorry, I made mistake when I transcribed example.( I have no information about debug functions too ).
This exampe don’t work. The function __qnx_debug_xfer don’t work when value Nid is 0 .
The Value Nid should be set as network ID Nid = getnid(), or virtual circuit ID if you
want work with another node e.g. pid_t Nid = qnx_vc_attach( 21, PROC_PID, 0, 0 )

Majo.

Phil Wilson <> wilson@cwnet.com> > wrote:
Thanks, however the call to __qnx_debug_xfer always returns -1…
I am new to this news group but not to QNX. But I have no information about
the debug functions. Anyone out there with this documentation?
BTW, I noticed that about a year ago someone else asked this very same
question. He was told to try popen(“sin ar”) . I suppose this would work,
but I prefer the Magic memory solution…

Any comments?

“Marian Oklapek” <> majo@microstep-mis.sk> > wrote in message
news:agc4vg$a0q$> 1@charon.microstep-mis.sk> …
Phil Wilson <> wilson@cwnet.com> > wrote:
I need to find a process argument list in code. I can’t seem to locate
it in
the _psinfo structure. Does anyone know how “sin ar” works?

Task sin args use function __qnx_debug_xfer (sys/debug.h).
Here is small example, how you can to gain process arguments of process
Pid.

First you should read psinfo of process, next counting position of cmd
item and read this item.
Second to read struct _proc_spawn, and extract arguments from this
structure.

pid_t Pid = 1;
nid_t Nid = 0;
!! nid_t Nid = getnid();

struct _psinfo PsInfo;
struct _proc_spawn *ProcSpawn;
union _debug_data Data;
unsigned MagicSel;
unsigned long MagicOff;
void *VoidPtr;
char *p;
int i;

if( (Pid = qnx_psinfo( Nid, Pid, &PsInfo, 0, 0 )) != -1 )
{
// Test for valid process
if( PsInfo.flags & ( _PPF_VID | _PPF_MID ) )
return;

// Count position of cmd in struct _magic
MagicOff = PsInfo.magic_off + offsetof( struct _magic, cmd );
MagicSel = PsInfo.magic_sel;

// Read item cmd from process Pid
if( __qnx_debug_xfer( Nid, Pid, _DEBUG_MEM_RD, &VoidPtr, sizeof( void

  • ), MagicOff, MagicSel ) != -1 )
    {
    // read struct _proc_spawn from address VoidPtr
    if( __qnx_debug_xfer( Nid, Pid, _DEBUG_MEM_RD, &Data, sizeof( union
    debug_data ), ( unsigned long ) VoidPtr, MagicSel ) != -1 )
    { ProcSpawn = ( struct _proc_spawn * ) &Data;
    p = ProcSpawn->data;

// Access to arguments
for( i=0; i < ProcSpawn->argc; i++ )
{ printf(“Arg%i is %s”, i, p );

// Warning ProcSpan->data can by up to 64K. I read only 512B. I don’t know
how many bytes
// function __qnx_debug_xfer can to transfer.
p += strlen( p ) + 1;

}
}
}
}


Good luck
Majo.

Realtime Technology Systems Pty Ltd
2 Hadleigh Circuit
Isabella Plains
ACT 2905
AUSTRALIA

Phone: 61-2-6291 3833
Fax: 61-2-6291 3838
Mobile: 0413 634 667
Email: geoff@rtts.com.au

Geoff <geoff@rtts.com.au> wrote:

This doesn’t work either. __qnx_debug_xfer() still returns -1 but the
errno has now changed to 89 (Unknown System Call).

It’s a pity there is no documentation of the debug functions. Sort of
like that lack of docs for QNX4 resource managers… and special double
underscore functions required there…

Geoff.

It should be work. I using QNX 4.25 (version 4.25L of Proc32 ) and have no problem.
Here is functional testing example which may help to you.

For compile use this line:

cc -ms -o sinarg -g sinarg.c

/**************************************************************************/
#include <stddef.h>
#include <stdio.h>
#include <sys/psinfo.h>
#include <sys/debug.h>
#include <sys/magic.h>
#include <sys/kernel.h>

void main( int argc, char *argv[] )
{
struct _psinfo PsData;
struct _proc_spawn *ProcSpawn;
union _debug_data Data;

pid_t Pid, Vid;
nid_t Nid;
int Ret, i;
unsigned short *Count;
unsigned long MagicOff;
unsigned MagicSel;
void *VoidPtr;
char *Cmd, *p;

// Setting nid value
switch( argc )
{
case 1:
Nid = getnid();
break;
case 2:
Nid = atoi( argv[1] );
break;
default:
printf(“Bad arguments \n”);
return;
break;
}

// Create virtual circuit
Vid = qnx_vc_attach( Nid, PROC_PID, 512, 0 );

// Get psinfo for every process on the station
while ( (Pid = qnx_psinfo( Vid, Pid, &PsData, 0, 0 )) != -1 ) {
if( (PsData.flags & _PPF_VID) || (PsData.flags & _PPF_MID) ) {
++Pid;
continue;
}

// Count position of cmd in struct _magic
MagicOff = PsData.magic_off + offsetof( struct _magic, cmd );
MagicSel = PsData.magic_sel;

// Read item cmd from process
if( __qnx_debug_xfer( Vid, Pid, _DEBUG_MEM_RD, &VoidPtr, sizeof( void * ) , MagicOff, MagicSel ) != -1 ) {

// Read struct _proc_spawn from process
if( __qnx_debug_xfer( Vid, Pid, _DEBUG_MEM_RD, &Data, sizeof( union _debug_data ) , ( unsigned long ) VoidPtr, MagicSel ) != -1 ) {
ProcSpawn = ( struct _proc_spawn * ) &Data;
p = ProcSpawn->data;

// Access to process arguments
printf("\n");
printf( "%s ", p );
for( i = 0; i < ProcSpawn->argc; i++ ) {
p += strlen( p ) + 1;
printf( "%s ", p );
}
}
}
++Pid;
}

printf( “\n” );

// Detach virtual circuit
qnx_vc_detach( Vid );
}