Difficulty: Easy
Correct Answer: $!
Explanation:
Introduction / Context:
Scripting often requires capturing the PID of a background task to wait on it, send signals, or monitor its status. POSIX shells expose special parameters for this purpose, enabling robust job control and automation patterns without resorting to parsing ps output.
Given Data / Assumptions:
Concept / Approach:
$! expands to the PID of the most recently executed background pipeline. Other parameters have different meanings: $# is the number of positional parameters, $0 is the script's name, and $ expands positional parameters as a single word. Thus, $! is the correct way to capture and reference a background job's process ID immediately after launching it.
Step-by-Step Solution:
Verification / Alternative check:
Test snippet: ( sleep 3 ) & echo $! prints the PID, demonstrating the variable's semantics in interactive and script contexts.
Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
$!.
Discussion & Comments