1

Possible Duplicate:
What does $$ mean in the shell?

$ ./cruncher & ./cruncher & ./cruncher &
$ ps -C cruncher -p $$ -o pid,state,cmd
PID S CMD
2588 S bash
2657 R /bin/sh ./cruncher
2658 R /bin/sh ./cruncher
2659 R /bin/sh ./cruncher

-C cmdlist      Select by command name.
                       This selects the processes whose executable name is
                       given in cmdlist.

-p pidlist      Select by PID.
                       This selects the processes whose process ID numbers
                       appear in pidlist.

Question> What is the meaning of $$?

Community
  • 1
  • 1
q0987
  • 34,938
  • 69
  • 242
  • 387
  • [$$ refers to the PID of the bash instance running the script](http://stackoverflow.com/a/78528/391104) – q0987 May 22 '12 at 13:56

2 Answers2

4

It has nothing to do with the ps command, $$ is substituted by the shell with its process ID.

glglgl
  • 89,107
  • 13
  • 149
  • 217
1

It's a built-in shell variable which holds the PID process ID.

Rahul
  • 76,197
  • 13
  • 71
  • 125