Process command line arguments

Somebody knows how to get command line startup arguments of SOME (any)
process form code of MY process?
Beforehand is grateful:)

Are you trying to get the arguments for another process from you own C
program? Something like ‘sin ar’ does?

If so, take a look at qnx_psinfo().

I think you have to get the info for a process and use that to get at the
argument lists. I don’t remember exactly how.

“Ivan Kulkov” <guard@crypto.ru> wrote in message
news:a94rl4$5pi$1@inn.qnx.com

Somebody knows how to get command line startup arguments of SOME (any)
process form code of MY process?
Beforehand is grateful:)

“Bill Caroselli (Q-TPS)” <QTPS@earthlink.net> wrote:

Are you trying to get the arguments for another process from you own C
program? Something like ‘sin ar’ does?

If so, take a look at qnx_psinfo().

I think you have to get the info for a process and use that to get at the
argument lists. I don’t remember exactly how.

It’s black magic.

A combination of qnx_debug_xfer() and _magic pointers.

You’re not supposed to do this in the ordinary run of things – why
do you want to do this?

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Then there’s always:
popen( “sin -P myprog ar”, ‘r’ );
and process the few lines that go around it.

Be aware that ‘sin ar’ only returns a limited number of characters for each
process found.

“David Gibbs” <dagibbs@qnx.com> wrote in message
news:a94v1o$33p$1@nntp.qnx.com

“Bill Caroselli (Q-TPS)” <> QTPS@earthlink.net> > wrote:
Are you trying to get the arguments for another process from you own C
program? Something like ‘sin ar’ does?

If so, take a look at qnx_psinfo().

I think you have to get the info for a process and use that to get at
the
argument lists. I don’t remember exactly how.

It’s black magic.

A combination of qnx_debug_xfer() and _magic pointers.

You’re not supposed to do this in the ordinary run of things – why
do you want to do this?

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

“Bill Caroselli (Q-TPS)” <QTPS@earthlink.net> wrote:

Then there’s always:
popen( “sin -P myprog ar”, ‘r’ );
and process the few lines that go around it.

Be aware that ‘sin ar’ only returns a limited number of characters for each
process found.

… and simply sticks a space between arguments without adding any
quotes or backslashes, which makes it impossible to find out which
spaces were originally contained in an argument.

\

Wojtek Lerch QNX Software Systems Ltd.

“David Gibbs” <dagibbs@qnx.com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:a94v1o$33p$1@nntp.qnx.com

“Bill Caroselli (Q-TPS)” <> QTPS@earthlink.net> > wrote:
Are you trying to get the arguments for another process from you own C
program? Something like ‘sin ar’ does?

If so, take a look at qnx_psinfo().

I think you have to get the info for a process and use that to get at
the
argument lists. I don’t remember exactly how.

It’s black magic.

A combination of qnx_debug_xfer() and _magic pointers.

You’re not supposed to do this in the ordinary run of things – why
do you want to do this?

I write the program which should do the following:

  1. Periodically to determine presence in a OS context of the certain
    processes.
    ( The processes are described in ini by a name of the module and arguments
    of start (command line))
  2. If any of controllable processes is absent in a OS context - program
    should start it.
    In a configuration file the number of allowable restarts of controllable
    processes is defined.

At first there was a problem:
Some executed modules can be started with various arguments.
Use qnx_psinfo allows me to find out only names of executable modules
started in ïó.
It is necessary to me to distinguish processes having one executable module
but different arguments of start.
The mechanism of reception of processes startup arguments is necessary for
this purpose.

As you have prompted me: in structure _psinfo there are fields indicating
the address of structure _magic (_psinfo.magic_sel, _psinfo.magic_offset?).
The structure _magic contains the pointer (magic32.cmd or magic16.sptrs [2])
to structure _proc_spawn.
In turn _proc_spawn contains the pointer (_proc_spawn.data) to the command
line of process startup.

Now problem another:
It is necessary to get access to structures _magic, _proc_spawn and
_proc_spawn.data of EACH controllable process.

I only begin to get acquainted with qnx.
And I would be very grateful for a brief example of use of function __
qnx_debug_xfer (probably for reception _magic).
Also it would be desirable to learn(find out) the description of arguments
__ qnx_debug_xfer and method of its(her) use.
I ask to excuse for importunity, but the decision of this problem is very
important for me.
I only beginning in QNX.

Yours faithfully in expectation of the answer, é×ÁÎ.


-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

Rather than have a application that queries the OS to look from certain
process names and arguments you could create an application that accepts an
ini file and starts the programs listed with their given options. The parent
then has a map of processes and startup options keyed buy pid. The added
bonus is that the parent will be signaled via SIGCHLD whenever a child dies.
The parent can then lookup the pid and restart the app (if max restarts has
NOT been exceeded).

Using this sol’n you remove the dependency on qnx_psinfo and qnx_debug_xfer.

“Ivan Kulkov” <guard@crypto.ru> wrote in message
news:a9gebn$9f5$1@inn.qnx.com

“David Gibbs” <> dagibbs@qnx.com> > ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:a94v1o$33p$> 1@nntp.qnx.com> …
“Bill Caroselli (Q-TPS)” <> QTPS@earthlink.net> > wrote:
Are you trying to get the arguments for another process from you own C
program? Something like ‘sin ar’ does?

If so, take a look at qnx_psinfo().

I think you have to get the info for a process and use that to get at
the
argument lists. I don’t remember exactly how.

It’s black magic.

A combination of qnx_debug_xfer() and _magic pointers.

You’re not supposed to do this in the ordinary run of things – why
do you want to do this?

I write the program which should do the following:

  1. Periodically to determine presence in a OS context of the certain
    processes.
    ( The processes are described in ini by a name of the module and
    arguments
    of start (command line))
  2. If any of controllable processes is absent in a OS context - program
    should start it.
    In a configuration file the number of allowable restarts of
    controllable
    processes is defined.

At first there was a problem:
Some executed modules can be started with various arguments.
Use qnx_psinfo allows me to find out only names of executable modules
started in ïó.
It is necessary to me to distinguish processes having one executable
module
but different arguments of start.
The mechanism of reception of processes startup arguments is necessary
for
this purpose.

As you have prompted me: in structure _psinfo there are fields indicating
the address of structure _magic (_psinfo.magic_sel,
_psinfo.magic_offset?).
The structure _magic contains the pointer (magic32.cmd or magic16.sptrs
[2])
to structure _proc_spawn.
In turn _proc_spawn contains the pointer (_proc_spawn.data) to the command
line of process startup.

Now problem another:
It is necessary to get access to structures _magic, _proc_spawn and
_proc_spawn.data of EACH controllable process.

I only begin to get acquainted with qnx.
And I would be very grateful for a brief example of use of function __
qnx_debug_xfer (probably for reception _magic).
Also it would be desirable to learn(find out) the description of arguments
__ qnx_debug_xfer and method of its(her) use.
I ask to excuse for importunity, but the decision of this problem is very
important for me.
I only beginning in QNX.

Yours faithfully in expectation of the answer, é×ÁÎ.


-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.

“Brown, Richard” <brownr@aecl.ca> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:a9h0hq$ncr$1@inn.qnx.com

Rather than have a application that queries the OS to look from certain
process names and arguments you could create an application that accepts
an
ini file and starts the programs listed with their given options. The
parent

Not in my case.
I write the program which should supervise ALREADY started (before its
start) processes.

then has a map of processes and startup options keyed buy pid. The added
bonus is that the parent will be signaled via SIGCHLD whenever a child
dies.
The parent can then lookup the pid and restart the app (if max restarts
has
NOT been exceeded).

Using this sol’n you remove the dependency on qnx_psinfo and
qnx_debug_xfer.

“Ivan Kulkov” <> guard@crypto.ru> > wrote in message
news:a9gebn$9f5$> 1@inn.qnx.com> …

“David Gibbs” <> dagibbs@qnx.com> > ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:a94v1o$33p$> 1@nntp.qnx.com> …
“Bill Caroselli (Q-TPS)” <> QTPS@earthlink.net> > wrote:
Are you trying to get the arguments for another process from you own
C
program? Something like ‘sin ar’ does?

If so, take a look at qnx_psinfo().

I think you have to get the info for a process and use that to get
at
the
argument lists. I don’t remember exactly how.

It’s black magic.

A combination of qnx_debug_xfer() and _magic pointers.

You’re not supposed to do this in the ordinary run of things – why
do you want to do this?

I write the program which should do the following:

  1. Periodically to determine presence in a OS context of the certain
    processes.
    ( The processes are described in ini by a name of the module and
    arguments
    of start (command line))
  2. If any of controllable processes is absent in a OS context - program
    should start it.
    In a configuration file the number of allowable restarts of
    controllable
    processes is defined.

At first there was a problem:
Some executed modules can be started with various arguments.
Use qnx_psinfo allows me to find out only names of executable modules
started in ïó.
It is necessary to me to distinguish processes having one executable
module
but different arguments of start.
The mechanism of reception of processes startup arguments is necessary
for
this purpose.

As you have prompted me: in structure _psinfo there are fields
indicating
the address of structure _magic (_psinfo.magic_sel,
_psinfo.magic_offset?).
The structure _magic contains the pointer (magic32.cmd or magic16.sptrs
[2])
to structure _proc_spawn.
In turn _proc_spawn contains the pointer (_proc_spawn.data) to the
command
line of process startup.

Now problem another:
It is necessary to get access to structures _magic, _proc_spawn and
_proc_spawn.data of EACH controllable process.

I only begin to get acquainted with qnx.
And I would be very grateful for a brief example of use of function __
qnx_debug_xfer (probably for reception _magic).
Also it would be desirable to learn(find out) the description of
arguments
__ qnx_debug_xfer and method of its(her) use.
I ask to excuse for importunity, but the decision of this problem is
very
important for me.
I only beginning in QNX.

Yours faithfully in expectation of the answer, é×ÁÎ.


-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.
\

Ivan Kulkov <guard@crypto.ru> wrote:

“David Gibbs” <> dagibbs@qnx.com
news:a94v1o$33p$> 1@nntp.qnx.com> …
“Bill Caroselli (Q-TPS)” <> QTPS@earthlink.net> > wrote:
Are you trying to get the arguments for another process from you own C
program? Something like ‘sin ar’ does?

If so, take a look at qnx_psinfo().

I think you have to get the info for a process and use that to get at
the
argument lists. I don’t remember exactly how.

It’s black magic.

A combination of qnx_debug_xfer() and _magic pointers.

You’re not supposed to do this in the ordinary run of things – why
do you want to do this?

I write the program which should do the following:

  1. Periodically to determine presence in a OS context of the certain
    processes.
    ( The processes are described in ini by a name of the module and arguments
    of start (command line))
  2. If any of controllable processes is absent in a OS context - program
    should start it.
    In a configuration file the number of allowable restarts of controllable
    processes is defined.

As others have suggested, using a starter program that tracks these
processes by starting them explicitly and then restarting them based
on SIGCHLD notification, and possibly a count of number of failures
would be good.

You say they’re already started on the system. How much control
of the system startup do you (the company you work for) have? I
expect you will get a better solution if you re-configure your setup
to handle that then trying to use these debug interfaces on an ongoing
basis.


I only begin to get acquainted with qnx.
And I would be very grateful for a brief example of use of function __
qnx_debug_xfer (probably for reception _magic).
Also it would be desirable to learn(find out) the description of arguments
__ qnx_debug_xfer and method of its(her) use.
I ask to excuse for importunity, but the decision of this problem is very
important for me.

As I’ve said, these are undocumented functions that are NOT intended for
general use. Using them as you want to use them is something that I
consider to be a BAD IDEA.

Ok,

here are some snippets from sin that might help to figure out what is
going on with these functions – I can’t give you more, I’ve never used
the functions, and no documentation for them exists that I know of.


/*

  • Buffers.
    */
    char treeline[512], treeflag;

void
struct _psinfo *proc;
long code_bytes, data_bytes, shared_bytes, dword;

if(__qnx_debug_xfer(vid, proc->pid, _DEBUG_MEM_RD,
&dword, sizeof(dword),
(unsigned)proc->magic_off + offsetof(struct _magic, sptrs[2]),
proc->magic_sel) != -1
&& dword
&& debug_read(vid, proc, treeline, sizeof(treeline),0, dword) != -1)
print_args((struct _proc_spawn *)treeline);
else
printf("%-32s", “Not available.”);
break;



print_args(sp)
struct _proc_spawn *sp;
{
char *cp = sp->data, *endcp = (char *)sp + sizeof(treeline);

while (sp->argc–) {
cp += strlen(cp) + 1; /* Skip first arg /
if(cp + strlen(cp) >= endcp) {
/

  • sp may be to small to hold all args so we check
  • for an overrun and print a … to let the user know.
    */
    sp->argc = 0;
    cp = “…”;
    }
    printf("%s ", cp);
    }
    }


    debug_read(pid_t vid, struct _psinfo *proc, char *buf, unsigned maxbytes,
    short unsigned segment, long unsigned off)
    {
    unsigned n, ret, seg;

/* segment may be 0 ; so that old portions of sin code which
built up a combined seg/offset in off can pass 0 and keep
the old functionality */

if (segment==0) {
if(proc->flags & _PPF_32BIT)
seg = proc->magic_sel;
else {
seg = off >> 16;
off &= 0xffff; /* bizarre; why limit to 1st 64k ?? /
}
} else {
if(proc->flags & _PPF_32BIT)
seg = proc->magic_sel; /
should we keep this here? */
else {
seg=segment;
}
}

n = min(maxbytes, 512); /* Limit to max allowed by the debug msg */

do {
ret = __qnx_debug_xfer(vid, proc->pid, _DEBUG_MEM_RD,
buf, n,
off, seg);
} while(ret == -1 && errno != EPERM && errno != ESRCH && (n -= 32) >= 64) ;

buf[n - 1] = ‘\0’; /* Make sure buf is null terminated. */

return(ret);
}


-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.