Re: How to get the pid of all children, grand children..../... of a process

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 30, 2006 at 12:08:45PM +0530, Gopala Krishna wrote:
> Good evening/morning/afternoon,
>  
> I knew a process ID which creates a pocess, which inturn creates a process,
> which in turn creates another process (like this down the line for about 10
> process).  Now I want to see what are all the process created down th line from
> the pid of the first process.  Is there any way/scheme to find it out.
>  
> Please let me know.
>  
> Thanks and regards,
> GOpal.

Hmm, it's an interesting question. In fact, you want to look at the tree
from the bottom to the top.

You cant the pid of the parent (with getppid()), but how can you get the
grand parent process ? One idea is to implement a signal handler which
executes the function getppid() on the parent : then you can get the pid
of the grand parent.
But since the parent of a process is often a shell instance, it's not
acceptable (you won't modify the shell code !:))

Well in fact, you have to access the process table structure : but from
user space, I guess it's impossible.

Fortunately, here comes the proc filesystem !
So, you have the pid of the father process : look at the file
/proc/'ppid'/status there should be a fild ppid : you have the pid of
your grand parent.
You can do a recursive function to find all the ancestors of your
process.
This solution is quite annoying since you have to handle files, but it
works.

If this solution is not acceptable for you, you can look at the pstree
source code.

I don't know if you wanted to do that in your own programm or just
wanted some soft to give you the entire tree (like pstree). Anyway... :)

-- 
tyler
tyler@xxxxxxxx


	

	
		
___________________________________________________________________________ 
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son interface révolutionnaire.
http://fr.mail.yahoo.com


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux