Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi guys! Given a process ID (PID 1

Status
Not open for further replies.

DZH

Programmer
Apr 12, 2002
26
ZA
Hi guys!

Given a process ID (PID), how do I get the child processes whose parent process is PID? The intent is to programmatically kill a process and all its child processes. If a child process is itself a parent of another process, then the "second generation" child processes should be killed as well. I would like to do this on Solaris using C and any of the scripting langs (SH, AWK, or PERL).

Thanks.
 
Though this is a "c" forum - you could easily do what you want in PERL alone - by using the readily available,
"ps -ef" command. This would be the most portable way.

Store the entire process list in a binary tree using Parent Process ID as the primary, find the requested PID in the list and traverse said list from that point.

From a "c" and Solaris perspective - check these:
man -s 4 proc (explains how to read the /proc filesystem)
procfs.h (header file for /proc system structs)
 
Hi,

There is another application "ptree" in UNIX. You can use this cammand in perl, even you don't need to make any binary tree, It will give you a full tree of given PID.

--Amar
 
Very good point, AmarG! On Solaris, ptree is found in /usr/proc/bin/ptree. This may not be in your default path, but it is certainly a good program. ptree is not available on all systems though.. HP/UX for instance has no such command.
 
Many thanks, AmarG. I was about to write that does exactly what ptree does. Now, I don't have to. Again, thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top