jobs
Overview
The jobs command displays the status of jobs in the current shell. It lists the jobs that are running in the background or stopped.
Syntax
jobs [options] [jobspec...]Common Options
| Option | Description |
|---|---|
-l |
List PIDs |
-p |
List PIDs only |
-n |
New jobs |
-r |
Running jobs |
-s |
Stopped jobs |
-x command |
Execute command |
Job States
| State | Description |
|---|---|
| Running | Currently executing |
| Stopped | Suspended |
| Done | Completed |
| Terminated | Killed |
| Suspended | Paused |
Key Use Cases
- Job monitoring
- Process control
- Background tasks
- Shell management
- Task scheduling
Examples with Explanations
Example 1: List Jobs
jobsShow all jobs
Example 2: Show PIDs
jobs -lList with process IDs
Example 3: Running Jobs
jobs -rShow running jobs
Common Usage Patterns
Check status:
jobs -lBackground job:
command & jobsStopped jobs:
jobs -s
Job Control
- Background (&)
- Foreground (fg)
- Stop (Ctrl-Z)
- Continue (bg)
- Kill (kill)
Additional Resources
Best Practices
- Monitor jobs
- Use job numbers
- Check status
- Clean up jobs
- Document tasks
Security Considerations
- Job ownership
- Process control
- Resource usage
- Shell access
- User permissions
Troubleshooting
- Hung jobs
- Zombie processes
- Status errors
- Shell issues
- Resource limits
Job Notation
- %n (job number)
- %string (prefix)
- %?string (contains)
- %+ (current)
- %- (previous)