When a script is launched from command prompt the shell will spawn a subprocess for that script. I want to show that relationship between terminal level process and its children using ps
in a tree style output.
How can I do this?
What I have tried so far
file: script.sh
#!/bin/bash
ps -f -p$1
Then I invoke the script from the command line passing in the process id of the terminal shell:
$ ./script.sh $$
What I want is something like this
- top level (terminal) shell process
- ./script.sh
- process for
ps
command itself
USER PID [..]
ubuntu 123 -bash
ubuntu 1234 \_ bash ./script.sh
ubuntu 12345 \_ ps auxf
what Im getting is:
PID TTY STAT TIME COMMAND
14492 pts/24 Ss 0:00 -bash
Best Answer
Try