nerdexam
CompTIA

LX0-104 · Question #2

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.. The $$ special parameter in shell scripting expands to the process ID (PID) of the shell in which it is executed. Therefore, echo $$ displays the PID of the current shell.

Shells, Scripting and Data Management

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

(25 responses)
  • A
    4% (1)
  • B
    92% (23)
  • C
    4% (1)

Why each option

The `$$` special parameter in shell scripting expands to the process ID (PID) of the shell in which it is executed. Therefore, `echo $$` displays the PID of the current shell.

AIt is the process ID of the echo command.

The `echo` command itself is a separate process, but `$$` does not represent its PID; rather, it represents the PID of the parent shell process.

BIt is the process ID of the current shell.Correct

The `$$` special parameter is a predefined shell variable that holds the process ID (PID) of the shell itself. When `echo $$` is executed, it prints the PID of the shell process that is running the `echo` command.

CIt is the process ID of the last command executed.

The `$$` special parameter refers to the current shell's PID, not the PID of the last command executed, which is typically stored in `$!` for background processes.

DIt is the process ID of the last command which has been placed in the background.

The `$$` special parameter does not refer to the PID of the last background command; that is stored in the `$!` variable.

Concept tested: Shell special parameters (PID)

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

Topics

#shell variables#process ID#bash features

Community Discussion

No community discussion yet for this question.

Full LX0-104 Practice