I can do ps -o "pid,ppid,args" -p my_pid to find the parent of my_pid.

I can continue ps -o "pid,ppid,args" -p previously_found_ppid in a loop until get to ppid=1.

However, I bet, there is a single call solution that would start with my_pid and list all its ancestors. Something reverse to pstree that starts with the parent and list all its descendants. Could you tell whether such Unix/Linux command is readily available?


It looks like pstree can do what you want, with it's -s Show parent processes of the specified process option

$ pstree -s 5698 

Or more info (arguments) and prettier with the -a option

mint@mint ~ $ pstree -s -a 5698 
          └─init --user
                  └─dbus-daemon --config-file=/etc/at-spi2/accessibility.conf ...

Or a few options together

$ pstree -s -p -a -G -l 5698 
          └─init,5379 --user
                  └─dbus-daemon,5698 --config-file=/etc/at-spi2/accessibility.conf --nofork --print-address 3

pstree can be used to print all the ancestors of a process. But latest Linux distributions uses systemd instead of init.

Example: pstree -p -s 6206 will give following output


A systemd, may refer to all the packages, utilities and libraries around daemon. It was designed to overcome the shortcomings of init [1].

reference [1]:https://www.tecmint.com/systemd-replaces-init-in-linux/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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