#include "sysdata.h" char *pidexecname(int pid) char *pidcmdline(int pid) char *pidpwd(int pid) int pidinfo(int pid, Pidstat *process)
pidcmdline returns the command line for process pid, subject to some limits on length, and provided the process has not mangled the line. The execution line does not, of course, indicate any file redirection.
pidpwd returns the current working directory for process pid.
pidinfo returns information about the process whose process id is pid in the Pidstat structure, which contains the following elements:
pidinfo should be called repeatedly with the same pidinfo structure for a particular pid. Furthermore, this structure should be initialized to zero on the first call.
void show_pidinfo ( int hdr, Pidstat *p ) { if ( hdr ) { printf ( " ppid uid %%cpu cputime ctime " "size rss state\n" ) ; } printf(" %5d %5d %6.2f%% %8.2f %8.2f %5.2f %5.2f %8s\n", p->ppid, p->uid, p->pcpu, p->cputime, p->ccputime, p->size/1024., p->rss/1024., p->state ) ; } void show_pid ( int pid ) { char *exec, *pwd, *cmdline, *s ; Pidstat process ; int i ; printf ( "\npid = %5d\n", pid ) ; exec = pidexecname(pid) ; printf ( "execnname = %s\n", exec ) ; pwd = pidpwd(pid) ; printf ( "pwd = %s\n", pwd ) ; cmdline = pidcmdline(pid) ; printf ( "cmdline = '%s'\n", cmdline ) ; free(exec) ; free(pwd) ; free(cmdline) ; memset ( &process, 0, sizeof(process)) ; if ( pidinfo ( pid, &process ) ) { complain ( 0, "pidinfo failed for pid #%d", pid); return ; } printf ( "Started = %s\n", s=strtime(process.started)); free(s) ; for ( i=0 ; i < 3 ; i++ ) { if ( pidinfo ( pid, &process ) ) { complain ( 0, "pidinfo failed for pid #%d", pid); return ; } else { show_pidinfo ( i==0, &process ) ; } sleep(1); } show_pidinfo ( 0, &process ) ; }