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]

 



--- Taha Hafeez Siddiqi <tawushafeez@xxxxxxxxx> wrote:

> On Tue, 2006-05-30 at 14:33 +0100, Ashok Sharma
> wrote:
> > 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.
> 
> 
> (Please correct me if I am wrong or partially
> right:) )
> fork() system calls return twice from the kernel,
> once it returns for
> the parent and in this case fork has a return value
> as the pid of the
> child as there is no other way for the parent to get
> the pid of the
> child.
> 
> The second return is for a new child (having
> different pid ofcourse).
> Here the return value is 0. It doesn't need the pid
> of the parent as it

Yes pid of child is same as id of parent and id of
child is zero.

Now if child forks() then grandchilds pid and id will
be what values? As id of child and pid of grandchild
must be same? Or does id of child change?

Best
Ashok
> can easily get that using getppid() call.
> 
> So, each process(child and parent) has its own pid
> and what you are
> confusing as pid is only the return value.
> 
> > 
> > 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
> > 
> This, I suppose, stands cleared now....
> 
> 
> 
> > Cheers 
> > ashok
> > 
> > 
> 
> Hope this helps....
> Taha
> 
> > 
> > 
> > 
> > 
> > --- 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/
> > 
> 
> 
> --
> Kernelnewbies: Help each other learn about the Linux
> kernel.
> Archive:      
> http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 
> 


Send instant messages to your online friends http://uk.messenger.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