Find children of the process

is there any way to know, who are children of the specific process ? for example those children which their parent ID is foo ?


Solution 1:

You are looking for the pstree command. pstree by itself will list all the processes in a tree form (like lsblk does). You can use the -p flag to get the PIDs listed as well, and the -s to show parent process as well:

$ pstree -p 602
udisksd(602)-+-{cleanup}(607)
             |-{gdbus}(605)
             |-{gmain}(603)
             `-{probing-thread}(606)

A (probably) POSIX-compliant way of getting the child PIDs (that I'd mentioned in the comments elsewhere):

ps -o ppid= -o pid= -A | awk '$1 == <some pid>{print $2}'

This tells ps to write the parent PID and PID of all processes (without headings), and then uses awk to see which lines have the given PID in the first field (the parent PID), and prints the corresponding second field (the child PID).

Solution 2:

If you just want to see the immediate children of a process whose PID is 123 you can use the ps command's --ppid option:

ps --ppid 123

You can combine that with the pidof command to get the children of a process by name i.e. given a process called foo

ps --ppid $(pidof foo)

Solution 3:

Another option is, to use System Monitor (comes pre-installed). In SM Menubar mark "Dependencies" option, under "View", to have a visual feedback, showing parent and children process(es) like show in the screenshot below.

I prefer the CL (Command Line) myself and suggest, that those who use Linux, in this case Ubuntu on a daily basis, wisely invest their time in learning the basic commands, over GUI Applications or at least are able to master both to a certain degree!

enter image description hereenter image description here