Inspect background jobs managed by the current interactive Bash.
Show the job number and the process ID.
Which Bash builtin is correct?
jobs displays the job table maintained by the current shell. The -l option adds process IDs to the usual job information.
Detailed explanation
ps -p $$Incorrect. ps -p $$ shows the shell process, not its job table.
Incorrect. ps -p $$ shows the shell process, not its job table.
jobs -lCorrect. jobs -l lists job numbers, status, commands, and PIDs.
Correct. jobs -l lists job numbers, status, commands, and PIDs.
pgrep -l bashIncorrect. pgrep searches process names and is not the shell's job table.
Incorrect. pgrep searches process names and is not the shell's job table.
wait -lIncorrect. wait synchronizes with jobs instead of listing them.
Incorrect. wait synchronizes with jobs instead of listing them.
Try it yourself
An example you can run in a temporary verification environment.
set -m; sleep 0.2 & jobs -l; waitExpected result
ジョブ番号、PID、Running、sleepを含む1行(書式はBashにより異なる)Key points
- jobs shows the current shell's jobs
- -l adds PIDs
- Its scope differs from ps's process list
Notes
- Environment: Bash 5.2
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.