How to get parent PID from a given child's PID?
I know I can manually check it under /proc
, I wonder if there is a smart/better way to achieve this in Ubuntu. Note the parent may or may not be killed.
Thanks
bashcommand lineprocess
How to get parent PID from a given child's PID?
I know I can manually check it under /proc
, I wonder if there is a smart/better way to achieve this in Ubuntu. Note the parent may or may not be killed.
Thanks
Best Answer
How to get a parent PID (PPID) from a child's process ID (PID) using the command-line
Use
ps -o ppid=
ps -o ppid= 2072
returns2061
, which you can easily use in a script etc.ps -o ppid= -C foo
gives the PPID of process with commandfoo
. You can also use the old fashionedps | grep
:ps -eo ppid,comm | grep '[f]oo'
.ps -f 2072
returnspstree
relation is:pstree -s -p 2072
: