nerdexam
LPI

102-500 · Question #13

What information is provided by the echo $$ command?

The correct answer is A. The process ID of the current shell. $$ is a special shell variable that holds the process ID (PID) of the current shell itself - so echo $$ prints that PID, making A correct. Why the distractors are wrong: B is wrong because no "following command" PID exists at the time echo $$ runs - $$ never looks ahead. C…

Shells and Shell Scripting

Question

What information is provided by the echo $$ command?

Options

  • AThe process ID of the current shell.
  • BThe process ID for the following command.
  • CThe process ID of the last command executed.
  • DThe process ID of the last command which has been placed in the background.
  • EThe process ID of the echo command.

How the community answered

(22 responses)
  • A
    86% (19)
  • B
    9% (2)
  • C
    5% (1)

Explanation

$$ is a special shell variable that holds the process ID (PID) of the current shell itself - so echo $$ prints that PID, making A correct.

Why the distractors are wrong:

  • B is wrong because no "following command" PID exists at the time echo $$ runs - $$ never looks ahead.
  • C describes $!... wait, no - $? holds the exit status of the last command, and $! holds the PID of the last backgrounded command; neither is $$.
  • D describes $!, the special variable for the last background job's PID - a common confusable.
  • E is wrong because $$ is evaluated by the shell before echo even runs - the echo process itself is never captured in $$.

Memory tip: Think of $$ as "self" - double-dollar, double-self. The shell telling you its own ID. Contrast with $! (the ! = "background bang") for background PIDs.

Topics

#Shell Variables#Process ID#Special Parameters#Shell Scripting

Community Discussion

No community discussion yet for this question.

Full 102-500 Practice