I'm using ps -eo ppid,pid,cmd
to view all process, and how can I format the output to view like below?
Only given PID and its ancestor will print (until init).
23464 current
|
23211 bash
|
23210 sshd: xxW
|
23193 sshd: WWcccv
|
728 /usr/sbin/sshd –D
|
1 init
I'm writing a script to view ancestral process using PID without using pstree
, if possible.
Best Answer
Maybe something like:
Which gives:
That's a bit sluggish as it runs one
ps
per process in the ancestry. You can improve it by runningps
to retrieve all the information at once and post process it withawk
for instance: