1. What is Job Control?
Job control allows you to manage multiple processes (jobs) started from the same shell. You can:
2. Important Commands
a) & (Run in Background)
$ sleep 60 &
[1] 2345
b) jobs (List Jobs)
Example:
$ jobs
[1]+ Running sleep 60 &
[2]- Stopped vim file.txt
c) fg (Bring Job to Foreground)
fg %[job_number]
Example:
$ fg %1
d) bg (Resume Job in Background)
bg %[job_number]
Example:
$ bg %2
3. Pausing and Resuming Jobs
Example Workflow:
$ vim file.txt # open vim
# press Ctrl+Z
[1]+ Stopped vim file.txt
$ bg %1 # resume in background
[1]+ vim file.txt &
$ fg %1 # bring back to foreground
4. Quick Tips
-
% = prefix to specify job number (from jobs command)
-
Use jobs -l to also see the PID of each job
-
You can have multiple jobs running simultaneously in the background
Summary Table
| Command |
Function |
command & |
Run command in background |
jobs |
List all jobs |
fg %n |
Bring job n to foreground |
bg %n |
Resume stopped job n in background |
Ctrl + Z |
Pause current foreground job |
If you want, I can draw a small diagram showing jobs moving between foreground, background, stopped, and running states. This makes it really easy to visualize.