When I consecutively issue multiple commands which create a new shell, e.g.

su user2
sudo su

Is there a command to show the “call stack”, i.e. a list of the commands which have not finished but created a new shell?

I might have issued some other commands among them, so the shell history won’t help. Moreover, I might have switched users and shells as shown in the above example.

I know I can find this information using the tree view in htop but can I get it directly using a command?

  • Those aren't subshells, but full processes. "Subshell" means a very particular thing re. the shell's environment, see e.g. Bash's manual – ilkkachu Feb 8 '18 at 13:12
  • @ilkkachu Thanks for your notice, I corrected my question. I was misled by the warning of the second mc instance: “Subshell support will be disabled.” – Melebius Feb 8 '18 at 13:25

You can use pstree (from PSmisc) for this:

pstree -s $$

The -s option shows the parents of the specified process identifier, and $$ is the current process’s identifier. pstree also shows the children of the specified process identifier, so you’ll end up with something along the lines of


(with screen, sudo, su, mc etc. in your case).

| improve this answer | |

you can try

ps -t $(tty)


  • tty will return your current tty (I assume you are in interactive session).
  • $( tty) will bring output in command line.
  • ps -t will list all process related to the tty.

you can add ps flag you like. (e.g.)

ps -t $(tty) -o stime,etime,args
| improve this answer | |
  • Fun with tsort: ps -t $(tty) -oppid=,pid= | tsort | xargs -n1 ps -o pid=,comm= -p – Kusalananda Feb 8 '18 at 11:26

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.