Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  28] [ 0]  / answers: 1 / hits: 38025  / 3 Years ago, tue, june 29, 2021, 12:16:46

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


More From » process

 Answers
3

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


[#23589] Tuesday, June 29, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
uccase

Total Points: 473
Total Questions: 100
Total Answers: 110

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;