Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question

4 Answers 4

up vote 17 down vote accepted

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

share|improve this answer

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 here enter image description here

share|improve this answer
1  
OT: What theme is that? –  muru Aug 18 at 16:28
1  
I use Ubuntu + GnomeShell 3.2.1 The theme is called "AdwaitaDark" which is a GTK3 theme, but it is customized and not available, like you see it in the screenshots. –  v2r Aug 18 at 16:36

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)
share|improve this answer

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

/proc/$mypid/task/$mypid/children

e.g.

$ cat /proc/3123/task/3123/children 
3131 3133

Similarly, you can get the parent process ID via the "PPid" entry in the file

/proc/$mypid/task/$mypid/status

e.g.

$ grep PPid /proc/3131/task/3131/status
PPid:   3123
$ grep PPid /proc/3131/task/3131/status | cut -f2
3123

I'm not sure how portable this is beyond Linux systems, though.

share|improve this answer
    
If portability is a concern: ps -o ppid= -o pid= -A | awk '$1 == <some pid>' | cut -f2 should be POSIX-compliant. –  muru Aug 23 at 22:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.