Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

What does the output of the command below mean? (result is positive integer)

echo $$
share|improve this question
1  
stackoverflow.com/questions/5163144/… is related –  kojiro Jan 20 '13 at 21:14

2 Answers 2

up vote 15 down vote accepted

The $$ variable in bash and other shells contains the process id of the shell.

See this Stack overflow question and this one also has more detail about what it is more precisely, and commands similar to it.

share|improve this answer
    
+1. Documented in the bash manual –  glenn jackman Jan 20 '13 at 19:02

As the other (accepted) answer indicated, the $ param represents the current process id (PID) of the current shell.

Echoing this param should work in most shells (not just Bash):

Bash:

$ echo $0
bash
$ echo $$
6780

Bourne:

$ echo $0
sh
$ echo $$
6988

C-Shell:

% echo $shell
/bin/csh
% echo $$
7613

It's important to note too, that commands from within the shell will run under the shell's parent process id (PPID).

$ echo $$
6780
$ ps -ef | grep 6780
aploetz   6780  6770  0 11:15 pts/2    00:00:00 bash
aploetz   8572  6780  0 11:34 pts/2    00:00:00 ps -ef
aploetz   8573  6780  0 11:34 pts/2    00:00:00 grep --color=auto 6780
share|improve this answer

Your Answer

 
discard

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.