Linux Job Control: Ctrl+Z and bg
Example: A Process That Actually Stops
Use this command:
Loading...This loop prints a number every second.
Step 1: Start the process
Loading...Output:
Loading...Step 2: Pause the process
Press:
Loading...You will see something similar to:
Loading...The process is now stopped.
It is not continuing to execute in the background. The loop is completely paused.
Step 3: Check the job
Run:
Loading...You will see:
Loading...You can wait for 10 seconds and check again. The process will still be stopped.
Step 4: Resume it with bg
Run:
Loading...Now the process continues from where it was paused, but it runs in the background.
For example, if you stopped it after:
Loading...it will continue with:
Loading...It does not continue counting while it is stopped.
Important Concept
Loading...Ctrl+Z stops the foreground job.bg resumes the stopped job in the background.fg resumes/brings the stopped or background job back to the foreground.Why This Example Is Useful
A command like:
Loading...can be confusing when learning job control because
sleep does not visibly show progress.The counting loop makes the behavior obvious:
Loading...The key idea is:
A stopped process makes no progress.bgis what resumes the process so it can continue working in the background.
Common Commands
Command | Purpose |
Ctrl+Z | Stop/pause the current foreground job |
jobs | Show jobs started from the current shell |
bg | Resume a stopped job in the background |
fg | Bring a background/stopped job to the foreground |
kill | Terminate a job/process |
Real-World Examples
The same concept applies to processes such as:
- Large file downloads
tarcompression
- Large
cpoperations
- Long-running scripts
- Compilation
- Data processing
If you stop such a process with
Ctrl+Z, its work is paused. Using bg allows it to continue running in the background..jpg?table=block&id=29d76b1d-f1a8-8072-a9bf-cc78d1c7d881&cache=v2)