jobs Command
The jobs command in Linux is a shell built-in command that lists the active jobs (processes) that are running in the current shell session. These jobs can be running in the foreground, in the background, or stopped.
Syntax
Description
The jobs command is part of job control in Unix-like operating systems, which allows users to manage multiple processes from a single shell. It provides information about the state of these jobs, including their job number, process ID (PID), and status (running, stopped, done).
Common uses include:
- Listing all active jobs in the current shell.
- Identifying background processes.
- Checking the status of suspended jobs.
- Managing jobs with
fg(foreground) andbg(background) commands.
Common Options
| Option | Description |
|---|---|
-l |
List process IDs in addition to the normal information. |
-p |
List only the process ID of the job's process group leader. |
-r |
Restrict output to running jobs. |
-s |
Restrict output to stopped jobs. |
Examples
List all active jobs
# Example Output: # [1]- Stopped vim # [2]+ Running sleep 600 &
Displays all jobs, including stopped and background processes.
List jobs with their process IDs
# Example Output: # [1]- 12345 Stopped vim # [2]+ 12346 Running sleep 600 &
Shows the PID for each job in addition to the standard output.
Bring a background job to the foreground
Brings job number 1 (as listed by jobs) to the foreground.
Send a suspended job to the background
Sends the most recently suspended job to the background.
Kill a background job
Terminates job number 2.