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
pscommand 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
pstree? – muru Feb 20 '16 at 09:50pstreeand couldn't get it to produce meaningful output, I thinkpstree $$just producedbash--pstreenot exactly what I was looking for. – the_velour_fog Feb 20 '16 at 09:53ps, so what else do you expect to see except forpstree? – muru Feb 20 '16 at 09:55pstree -p $$? Or, if you want more of the command line show,pstree -pa $$. Or, if you want to show all parent processes going up,pstree -psa $$. – muru Feb 20 '16 at 10:04pstree -alp 1– Iceberg Feb 01 '21 at 16:31