Using pstree -p $$ works for me on macOS Sonoma with Homebrew's pstree, executing it inside a zsh shell running inside the macOS Terminal.app:
>0@16:32:05 L1 :~ % pstree -p $$ -+= 00001 root /sbin/launchd \-+= 03998 roup /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal \-+= 51052 root login -pf roup \-+= 51053 roup -zsh \-+= 51139 roup pstree -p 51053 \--- 51140 root ps -axwwo user,pid,ppid,pgid,command >0@16:32:11 L1 :~ % bash bash-5.2$ zsh >0@16:32:18 L3 :~ % pstree -p $$ -+= 00001 root /sbin/launchd \-+= 03998 roup /System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal \-+= 51052 root login -pf roup \-+= 51053 roup -zsh \-+= 51142 roup bash \-+= 51143 roup zsh \-+= 51180 roup pstree -p 51143 \--- 51181 root ps -axwwo user,pid,ppid,pgid,command >0@16:32:27 L3 :~ %
Notice the nested shells listed in the second execution of pstree after I created a bash then a zsh nested sub-shells. The zsh shell prompt also shows the shell nested level, which is 3 on the second occurrence.
On Kali Linux, pstree -s $$ works, but lists the processes on a single line:
┌──0─L:1-[~] └─$ pstree -s $$ systemd───qterminal───zsh───pstree ┌──0─L:1─[~] └─$ bash ┌──[~] └─$ zsh ┌──0─L:3─[~] └─$ pstree -s $$ systemd───qterminal───zsh───bash───zsh───pstree ┌──0─L:3─[~] └─$
The -p options prints the PIDs:
┌──1─L:3─[~] └─$ pstree -s -p $$ 1 ⨯ systemd(1)───qterminal(1653597)───zsh(1653600)───bash(1653819)───zsh(1653855)───pstree(1655673)
pstree?pstreeand couldn't get it to produce meaningful output, I thinkpstree $$just producedbash--pstreenot exactly what I was looking for.ps, so what else do you expect to see except forpstree?pstree -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 $$.