|
October 2001
Shell Corner: PST
Hosted by Ed Schaefer
Tracing Shell Ancestry
Every active Unix program or process traces its ancestry back to the init process. When the system boots, the init process spawns from process 0. Yngve Clausen (yngve.clausen@itpp.no) sent me PST, a Korn script that traces a Unix process (PID) by parent processes (PPID) up to the Unix init process. PST can also recursively trace a PID's child processes down to its last spawned PID. PST is similar to the pstree command available on some Unix variants.
Testing PST
To test Yngve's PST script, I required persistent, manageable process table entries. I settled on three tiny "C" programs, a.out, b.out, and c.out, where a.out, using a system call, begets b.out. b.out, using another system call, begets c.out, which prompts the user to press a key. The test source is:
/* a.c: compile: cc a.c -o a.out */
#include <stdio.h>
main()
{
system("./b.out");
} /* end a.c */
/* b.c: compile: cc b.c -o b.out */
#include <stdio.h>
main()
{
system("./c.out");
} /* end b.c */
/* c.c: compile: cc c.c -o c.out */
#include <stdio.h>
main()
{
printf("Press a key ");
getchar();
} /* end c.c */
After executing a.out in another session, I determine the PID of c.out with ps -ef|grep c.out:
eds 22919 22918 0 08:00:43 pts/3 0:00 sh -c ./c.out
eds 22920 22919 0 08:00:43 pts/3 0:00 ./
|