jobs Command Cheat Sheet
The jobs command displays the status of jobs in the current shell session. A "job" is a process started by the shell.
Synopsis
jobs [options] [jobID...]
Job Control Basics
1. Starting a Background Job (&)
Append & to any command to run it in the background immediately.
sleep 1000 &
# Output: [1] 12345
[1]: Job ID (JID)
- 12345: Process ID (PID)
2. Suspending a Foreground Job (Ctrl+Z)
If you are running a command (e.g., vim or top) and want to pause it to use the terminal:
Press Ctrl+Z.
[2]+ Stopped vim file.txt
3. Listing Jobs
jobs
[1]- Running sleep 1000 &
[2]+ Stopped vim file.txt
+: The "current" job (default for fg/bg).
- -: The "previous" job.
Managing Jobs
Foreground (fg)
Bring a job to the foreground.
fg %1 # Bring job 1 to foreground
fg # Bring "current" (+) job to foreground
Background (bg)
Resume a "Stopped" job in the background (keep it running, but free up the terminal).
bg %2 # Start job 2 in background
Kill a Job
You can use the Job ID with kill.
kill %1
kill -9 %1
Jobs Options
Show PIDs (-l)
List jobs with their Process IDs.
jobs -l
[1]+ 12345 Running sleep 1000 &
Show Only PIDs (-p)
Useful for scripting.
jobs -p
12345
Show Running/Stopped Only
jobs -r # Running only
jobs -s # Stopped only
Disowning Jobs
If you close the terminal, all jobs usually die (SIGHUP). To prevent this:
disown
Removes the job from the shell's job table. It keeps running but you can no longer control it with fg/bg.
disown %1
nohup
Use nohup before starting the command to ignore SIGHUP signals.
nohup long_script.sh &
Practical Workflow
- Start a long compile:
make & - Realize you need to edit a file:
vim config.h - Forgot to check load:
Ctrl+Z(pause vim) - Check
htop - Resume vim:
fg
Notes
- Job ID vs PID:
%1is a Job ID (shell specific).12345is a PID (kernel global). jobsis a shell builtin. It does not work across different terminal tabs.