nerdexam
LPI

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…

Shells and Shell Scripting

Question

When the command echo $$ outputs 12942, what is the meaning of 12942?

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)
  • A
    7% (4)
  • B
    79% (44)
  • C
    13% (7)
  • D
    2% (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 echo runs as a child process with its own distinct PID; $$ is evaluated by the shell before echo even 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

#Shell variables#Process ID#Special parameters#Shell scripting

Community Discussion

No community discussion yet for this question.

Full 102-500 Practice