Getting Process Arguments QNX 4.25

Good day,

People I’m having problems getting process arguments; It’s not as simple as it seems to be.

I’m trying to do an application able to slay and rise programs and apps (Some kind of Task Manager), but due to a program could be raised many times passing different arguments, it’s not enough having the PID, I also need to know the arguments just to kill the right one and avoid problems.

I’m using C. Function qnx_psinfo gives me some important info but not enough to get a process arguments or parameters. Using qnx6, I found the way to do this, but now in QNX 4.25 I do not know how to do that and it kills me.

Does anyone know how to do THISSS pleaseee???

use popen to run “sin ar” and parse the return data

In qnx4 it is possible to use qnx_psinfo() and __qnx_debug_xfer() to read arguments directly from memory of a process.
However the qnx_debug_xfer has a “feature” which enables it write into read-only mapped memory owned by another process.
This example reads the arguments inefficiently, it could be optimized to read blocks.

[code]qnx_psinfo(PROC_PID, pid, &psdata, 0, NULL);

magic_off = psdata.magic_off + offsetof(struct _magic, cmd);
magic_sel = psdata.magic_sel;

__qnx_debug_xfer(PROC_PID, psdata.pid, _DEBUG_MEM_RD, &cmd_magic_ptr, sizeof(void *), magic_off, magic_sel);

__qnx_debug_xfer(PROC_PID, psdata.pid, _DEBUG_MEM_RD, buffer, sizeof(struct _proc_spawn) - 1, (unsigned long)cmd_magic_ptr, magic_sel)

proc_spawn = (struct _proc_spawn *)buffer;
args_parsed = 0;
p = buffer + sizeof(struct _proc_spawn) - 1;

for (i = 0; i < MAX_SIZE - sizeof(struct _proc_spawn) - 1 - 1; ++i, ++p)
{
if (__qnx_debug_xfer(PROC_PID, psdata.pid, _DEBUG_MEM_RD, p, 1, (unsigned long)cmd_magic_ptr + sizeof(struct _proc_spawn) - 1 + i, magic_sel) == -1)
return 0;

if (*p == 0)
	if (args_parsed++ == proc_spawn->argc)
		break;

}

p = proc_spawn->data;

for (i = 0; i < proc_spawn->argc + 1; ++i)
{
printf("’%s’\n", p);
p += strlen(p) + 1;
}[/code]

Mezek i have to say:
It didn’t work
Even when it’s to clean the way you suggest i wasn’t able to make it work couldn’t find the function __qnx_debug_xfer(), by the other hand i was able to do it using ianc method even when it’s not to clean, but it works.

Mezek could you post the libraries and .h files i need to make it work?

Hello,
It works for me just fine.

Did you search your development machine include files for __qnx_debug_xfer ?
On mine its in /usr/include/sys/debug.h

And by the way “sin ar” will return incomplete args if they are longer than about 500 Bytes.
(Which is unacceptable in our production environment.)