Where can I find my (current shell process') PID?
11,950
The special variable $$
is the current pid of the shell you are running, for any Bourne compatible (and, so, POSIX) shell.
Related videos on Youtube
Author by
John Hinnegan
Updated on September 18, 2022Comments
-
John Hinnegan over 1 year
I'm on OS X using ZSH (have lots of homebrew stuff, too).
I'd like to know the PID of my current terminal.
(I'm learning more about process management on *nix systems, pstree and the like, and so this is more an academic question vs. a specific use case I'm trying to solve)
EDIT: to clarify, I'm referring to the process that is running my current terminal/commandline.
-
Keith Thompson about 12 yearsWhat you're looking for is the PID of your current shell process. In your case, that's going to be a
zsh
process. The terminal doesn't have a PID. -
John Hinnegan about 12 yearsThanks for clarifying what I was looking for. Updating the Question to be more searchable.
-
-
Keith Thompson about 12 yearsAnd for csh and tcsh (and Perl).
-
PJSCopeland about 8 yearsWorks in Ruby too
-
OJFord over 5 years
$fish_pid
(though$$
will warn you, and tell you about$fish_pid
)