I know the full command "/bin/child_process" or its pid (3996 in this case) and I'm running ps auxf
and then visually identifying its ancestor process /bin/parent_process foobar
.
root 3227 0.0 0.0 992 296 ? S<s 10:35 0:00 /bin/parent_process foobar
20058 3987 0.0 0.0 17716 1452 ? S<s 10:35 0:00 \_ /bin/bash
20058 3989 0.0 0.0 19240 1728 ? S< 10:35 0:00 \_ /bin/bash other_args
20058 3996 0.2 1.5 1621804 546104 ? S<l 10:35 0:54 \_ /bin/child_process
The ancestor process may not always be 3 levels away. Is there a way I can automate this with a command such that I could supply just the pid 3996
or the command /bin/child_process
and get out /bin/parent_process foobar
? In particular, it will always say /bin/parent_process
, but it will have a different argument than foobar
every time. The output of ps auxf
is very difficult to traverse as a hierarchy to determine a particular ancestor process.