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

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

 



Here is a related question.
When I fork() from a process a parent process with
some id is created together with a child process with
pid same a id of parent and id (of child) is zero. 

Now if from a child I fork() again then what will be
the pid and id of the child (or grand child) now. Both
cannot be zero again and what happens if I fork again
from the grand child?

Pl. clear my doubt

Cheers 
ashok






--- Gopala Krishna <gopalakrishna.n.m@xxxxxxxxx>
wrote:

> >
> > 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... :
> 
> 
> 
> In My case, I knew only pid of the first process. I
> want the top down
> approach rather than the bottom up (i.e if I know
> child, I know parent. but,
> my requirement is to find out child and it's grand
> children, If I know the
> parent pid). Currently I am going through pstree
> code.
> 
> Thanks and regards,
> Gopal.
> 



	
	
		
___________________________________________________________ 
Win tickets to the 2006 FIFA World Cup Germany with Yahoo! Messenger. http://advision.webevents.yahoo.com/fifaworldcup_uk/

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