TrumanWong

jobs

Displays the status of the job.

Summary

jobs [-lnprs] [jobspec ...]
jobs -x command [args]

The main purpose

  • Shows the status of the job.
  • Lists active jobs.
  • List stopped jobs.

Options

-l additionally lists PIDs in job information.
-n List only jobs whose status has changed since the last notification.
-p List only PIDs.
-r Output only running jobs.
-s Outputs only stopped jobs.

return value

The return status is success unless an illegal option is given or an execution error occurs.

If executed using jobs -x command [args] form, the return value is the exit status of command.

example

[user2@pc] ssh 192.168.1.4
pc@192.168.1.4's password:
# Press ctrl+z at this time to stop the interaction.
[1]+ Stopped ssh 192.168.1.4

[user2@pc] sleep 60 &
[2] 13338

[user2@pc] jobs
[1]- Stopped ssh 192.168.1.4
[2] Running sleep 60 &

[user2@pc] jobs -l
[1]- 12927 Stopped ssh 192.168.1.4
[2] 13338 Running sleep 60 &

[user2@pc] jobs -p
12927
13338

[user2@pc] jobs -s
[1]- Stopped ssh 192.168.1.4

[user2@pc] jobs -r
[2] Running sleep 60 &

[user2@pc] kill -9 12927
[2] Done sleep 60

[user2@pc] jobs -n -l
[1]+ 12927 Killed ssh 192.168.1.4

[user2@pc] jobs -n -l

Notice

  1. The job control commands of bash include bg fg kill wait disown suspend.
  2. This command can only be executed when the set option monitor is turned on; to view the job control status: enter set -o to view the monitor line; execute set -o monitor or set -m to turn it on this option.
  3. This command is a built-in bash command. For related help information, please see the help command.