mirror of
https://github.com/jbranchaud/til
synced 2026-01-02 22:58:01 +00:00
1.2 KiB
1.2 KiB
List PID And Name Of Current Shell Process
In Julia Evans' How to add a directory to your PATH, she shows off an odd-looking command for determining what shell (e.g. bash or zsh) you are currently running.
$ ps -p $$ -o pid=,comm=
38105 -zsh
I already know I'm running zsh, but I thought this command was interesting
enough to dig into and break down.
- The
pscommand lists processes that "have controlling terminals" - The
$$is a special shell variable representing the PID of the current process (tryecho $$) - The
-pflag allows you to specify a PID forpsto grab, in this case, the$$PID - The
-oflag allows us to specify the output format, such as the PID and command name - The
=afterpidandcommtellpsto exclude headers from the output
Additionally, I noticed that it output -zsh (not just zsh). That leading
hyphen seems to indicate that this zsh process is a login
shell. That means it was the
process used to initiate an interactive shell session and something like the
.zprofile would have been sourced as part of that.