Unix Review > Archives > 2001 > October 2001

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 ./

				  

Sys Admin Spotlight

CMP DevNet Spotlight

C++/CLI: Cloning
Making copies of heap-based objects

In the News

CD-ROM

Sys Admin and The Perl Journal CD-ROM version 11.0

Version 11.0 delivers every issue of Sys Admin from 1992 through 2005 and every issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!




MarketPlace

Instant Answers to Your IT & Business Questions
Sign Up & Get Full Access To The Definitive Online Book Collection With SkillSoft's Books24x7�.

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.

BugSplat - Automatic Crash Analysis
Fast online exception analysis. Capture customer crash data online.

Flowcharts from C/C++ code -- Free trial download
Understand C/C++ code in less time. A new team member ? Inherited legacy code ? Get up to speed faster with Crystal Flow for C/C++. Code-formatting improves readability. Flowcharts are integrated with code browser. Export flowcharts to Visio.

Wanna see your ad here?