nerdexam
Linux_Foundation

LFCS · Question #254

In the following command and its output, echo $$ 12942 which of the following is 12942?

The correct answer is B. The process ID of the current shell. This question tests knowledge of special Bash shell variables, specifically what $$ expands to.

Submitted by fatima_kr· Apr 18, 2026Essential Commands

Question

In the following command and its output, echo $$ 12942 which of the following is 12942?

Options

  • AThe process ID of the echo command.
  • BThe process ID of the current shell.
  • CThe process ID of the last command executed.
  • DThe process ID of the last backgrounded command.

How the community answered

(27 responses)
  • B
    89% (24)
  • C
    7% (2)
  • D
    4% (1)

Why each option

This question tests knowledge of special Bash shell variables, specifically what `$$` expands to.

AThe process ID of the echo command.

The process ID of the `echo` command would be a child process, not the current shell's PID, which `$$` refers to.

BThe process ID of the current shell.Correct

In Bash, `$$` is a special parameter that expands to the process ID (PID) of the current shell process. When `echo $$` is executed, the shell substitutes `$$` with its own unique process identifier, which is then printed to standard output.

CThe process ID of the last command executed.

The process ID of the last command executed is not represented by `$$` but can be found using other means, such as `!$`, in some contexts.

DThe process ID of the last backgrounded command.

The process ID of the last backgrounded command is typically referred to using job control variables or `!$`, not `$$`.

Concept tested: Bash special variable `$$`

Source: https://www.gnu.org/software/bash/manual/bash.html#Special-Parameters

Topics

#Shell special variables#Process ID (PID)#Bash commands#Shell scripting basics

Community Discussion

No community discussion yet for this question.

Full LFCS Practice