102-500 · Question #180
When the command echo $$ outputs 12942, what is the meaning of 12942?
The correct answer is B. It is the process ID of the current shell. $$ is a special shell variable that always holds the process ID (PID) of the current shell itself - so 12942 is the PID of the running shell session that executed the command. Why the distractors are wrong: A is wrong because echo runs as a child process with its own distinct…
Question
Options
- AIt is the process ID of the echo command.
- BIt is the process ID of the current shell.
- CIt is the process ID of the last command executed.
- DIt is the process ID of the last command which has been placed in the background.
How the community answered
(56 responses)- A7% (4)
- B79% (44)
- C13% (7)
- D2% (1)
Explanation
$$ is a special shell variable that always holds the process ID (PID) of the current shell itself - so 12942 is the PID of the running shell session that executed the command.
Why the distractors are wrong:
- A is wrong because
echoruns as a child process with its own distinct PID;$$is evaluated by the shell beforeechoeven spawns. - C is wrong - that's
$?, which holds the exit status (not PID) of the last command; there is no built-in variable for the PID of the last foreground command. - D is wrong -
$!holds the PID of the most recently backgrounded job, not$$.
Memory tip: Think of $$ as the shell asking "who am I?" - the double dollar sign refers to itself. Pair it with $! ("last background job") and $? ("last exit status") as the three most common special variables to know.
Topics
Community Discussion
No community discussion yet for this question.