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.
Question
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)- A4% (1)
- B88% (21)
- C8% (2)
Why each option
The special variable `$$` in a shell environment expands to the process ID (PID) of the current shell process.
`$$` refers to the shell's PID, not the PID of the `echo` command itself, which would be a child process.
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.
The exit status of the last command is `$?`, not `$$`.
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
Community Discussion
No community discussion yet for this question.