Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
What 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. – Keith Thompson Mar 5 '12 at 4:57
Thanks for clarifying what I was looking for. Updating the Question to be more searchable. – John Hinnegan Mar 5 '12 at 5:36
up vote 10 down vote accepted

The special variable $$ is the current pid of the shell you are running, for any Bourne compatible (and, so, POSIX) shell.

share|improve this answer
And for csh and tcsh (and Perl). – Keith Thompson Mar 5 '12 at 4:56
This works in ZSH, thanks – John Hinnegan Mar 5 '12 at 5:35
Works in Ruby too – PJSCopeland Apr 19 at 2:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.