is there any way to know, who are children of the specific process ? for example those children which their parent ID is foo ?
is there any way to know, who are children of the specific process ? for example those children which their parent ID is foo ?
You are looking for the
pstree
command.pstree
by itself will list all the processes in a tree form (likelsblk
does). You can use the-p
flag to get the PIDs listed as well, and the-s
to show parent process as well:A (probably) POSIX-compliant way of getting the child PIDs (that I'd mentioned in the comments elsewhere):
This tells
ps
to write the parent PID and PID of all processes (without headings), and then usesawk
to see which lines have the given PID in the first field (the parent PID), and prints the corresponding second field (the child PID).If you just want to see the immediate children of a process whose PID is
123
you can use theps
command's--ppid
option:You can combine that with the
pidof
command to get the children of a process by name i.e. given a process calledfoo
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!
I'm not an expert, but reading the above answers it seemed to me that there is probably a more direct way to do this via the proc filesystem, e.g. for programmatic use in a script rather than human-readable display. And indeed there is: for a process with ID code $mypid, its child processes are listed in
e.g.
Similarly, you can get the parent process ID via the "PPid" entry in the file
/proc/$mypid/task/$mypid/status
e.g.
I'm not sure how portable this is beyond Linux systems, though.
if you want to see just the first-level children of a given parent process
<pid>
id look in/proc/<pid>/task/<tid>/children
entry.Note that this file contains the pids of first-level child processes. for the whole process tree, do it recursively.
this https://lwn.net/Articles/475688/ contains more information about it.