Operating System - HP-UX
1819794 Members
3192 Online
109607 Solutions
New Discussion юеВ

Long command line and pstat_getproc()

 
SOLVED
Go to solution
Michael Goltsman
New Member

Long command line and pstat_getproc()

Hi,

I need to get long (more than 128 chars) command lines out of pstat_getproc(). Currently pst_cmd is 64 bytes long and pst_ucomm is 17 bytes long.
I know It's possible as ps(1) does it in UNIX95 mode on the same machine.

What should I do?

Regards,
Mike
7 REPLIES 7
Mike Stroyan
Honored Contributor

Re: Long command line and pstat_getproc()

A patched ps on 11i v1 uses pstat_getcommandline(). That is not available as a documented and supported interface until 11i v1.6 or 11i v2. You can read about the call in the system calls section of
http://www.docs.hp.com./hpux/onlinedocs/B2355-60103/B2355-60103.html
Michael Goltsman
New Member

Re: Long command line and pstat_getproc()

1. I have HP-UX B.11.11.
2. I tried to use pstat_getcommandline() and link failed.

Any help?

Regards,
Mike
Mike Stroyan
Honored Contributor

Re: Long command line and pstat_getproc()

You could just use popen to get the information from ps.

#include
#include
#include

char *getcommandline(int pid)
{
char command[500];
static char args[1024];
FILE *pipe;
int result;
char *newline;
sprintf(command, "UNIX95=1 /usr/bin/ps -p %d -x -o args=", pid);
pipe = popen(command, "r");
result = fread(args, 1, 1023, pipe);
pclose(pipe);
args[result] = 0;
newline = strchr(args, '\n');
if (newline) {
*newline = 0;
}
return args;
}

int main(int argc, char *argv[])
{
int i;
for (i=1; i printf("%s\n", getcommandline(atoi(argv[i])));
}
return 0;
}
Michael Goltsman
New Member

Re: Long command line and pstat_getproc()

Unfortunately, I can't do it. This ps should run almost every second :-(
Ermin Borovac
Honored Contributor
Solution

Re: Long command line and pstat_getproc()

Have a look at document KBRC00006317 in technical knowledge base. Here is a code sample from this document that demonstrates how to get up to 1024 chars for the command (as with 'ps -x'). Please note that PSTAT_GETCOMMANDLINE interface is unsupported.

#include
#include
#define MAX_LENGTH (1024)
main (argc, argv) int argc; char *argv[]; {
int pid;
char long_command [MAX_LENGTH];
union pstun pu;

pid = atoi(argv[1]);
pu.pst_command = long_command;
if (pstat(PSTAT_GETCOMMANDLINE, pu, MAX_LENGTH, 1, pid) == -1) {
printf("ERROR: pstat() failure using pid(%d)\n", pid);
exit(-1);
}
printf("pid %d = %s\n", pid, pu.pst_command);
}
Bill Hassell
Honored Contributor

Re: Long command line and pstat_getproc()

> This ps should run almost every second :-(

Be sure that you pick a specific process or perhaps a user list. ps -e is a VERY expensive command to be used on a busy machine and may take longer than 1 second to run. If you need to monitor a specific process, use the PID and never use grep to locate processes.


Bill Hassell, sysadmin
Michael Goltsman
New Member

Re: Long command line and pstat_getproc()

Thank you very much Ermin. It works.