nerdexam
CompTIA

LX0-104 · 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.. The special variable $$ in a shell environment expands to the process ID (PID) of the current shell process.

Shells, Scripting and Data Management

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

(24 responses)
  • A
    4% (1)
  • B
    88% (21)
  • C
    8% (2)

Why each option

The special variable `$$` in a shell environment expands to the process ID (PID) of the current shell process.

AThe process ID of the echo command.

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

BThe process ID of the current shell.Correct

The special shell variable `$$` always expands to the process ID of the shell that is currently executing, making 12942 the PID of the current shell.

CThe process ID of the last command executed.

The exit status of the last command is `$?`, not `$$`.

DThe process ID of the last backgrounded command.

The PID of the last backgrounded command is `$!`, not `$$`.

Concept tested: Shell special variables (PID)

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

Topics

#bash variables#process ID#shell scripting

Community Discussion

No community discussion yet for this question.

Full LX0-104 Practice