在HPUX 11.31中,这有效:
#include <sys/pstat.h>
char* tmp = (char*)malloc(256);
pstat_getcommandline(tmp, sizeof(char)*256, (size_t)1, (int)pid)
但是在HPUX 11.11上,pusat_getcommandline未在/usr/include/sys/pstat.h中定义。我试过直接调用pstat()(传递PSTAT_GETCOMMANDLINE作为第一个参数,确实碰巧在11.11的/usr/include/sys/pstat/pstat_ops.h中定义),但是这个失败了。我注意到在11.11的/usr/include/sys/pstat.h中的pstun联合中没有定义pst_command_name。
是否有一些替代方法可以在HPUX 11.11上获取命令行?
答案 0 :(得分:1)
适用于HPUX 11.11:
#include <sys/pstat.h>
char* tmp = (char*)malloc(64);
struct pst_status s;
pstat_getproc(&s,sizeof(s), 0, (int)pid)
tmp = strdup(s.pst_cmd);