• Antelope Release 5.9 Mac OS X 10.13.2 2019-05-01

 

NAME

pidexecname, pidpwd, pidcmdline, pidinfo - get process information for a pid

SYNOPSIS

#include "sysdata.h"

char *pidexecname(int pid)
char *pidcmdline(int pid)

char *pidpwd(int pid)

int pidinfo(int pid, Pidstat *process)

DESCRIPTION

pidexecname returns the path to the executable for process pid.

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.

EXAMPLE



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 ) ;
}

RETURN VALUES

returns zero for success, -1 for failure, and leaves messages on the error log.

LIBRARY

$(STOCKLIBS)

AUTHOR

Daniel Quinlan
Printer icon