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]

 



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.

There's a command called pstree which displays all processes as a tree. pstree <pid> displays from the specified pid. But perhaps you wanted to do this within a program instead of from a user terminal?

If you want it in your code, you can access the /proc/PID/status file, where you have a PPid (parent Pid) field. I think this is what pstree does.

However, I am not sure this is always good (or possible).
Consider process A creating B which creates C.

pstree will show:
init -> A -> B -> C

Now if B dies pstree will show:

init -> A
     -> C


AFAIK, processes whose parent dies become children of init.
I don't know how (or if) you can retrive the info that C is a descendant of A.


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