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.

Share:
11,950

Related videos on Youtube

John Hinnegan
Author by

John Hinnegan

Updated on September 18, 2022

Comments

  • John Hinnegan
    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
      Keith Thompson about 12 years
      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.
    • John Hinnegan
      John Hinnegan about 12 years
      Thanks for clarifying what I was looking for. Updating the Question to be more searchable.
  • Keith Thompson
    Keith Thompson about 12 years
    And for csh and tcsh (and Perl).
  • PJSCopeland
    PJSCopeland about 8 years
    Works in Ruby too
  • OJFord
    OJFord over 5 years
    $fish_pid (though $$ will warn you, and tell you about $fish_pid)