jobs
Command in Linux
Summary
The jobs
command in Linux provides information about background processes and their status. It allows you to manage and interact with processes that are running in the background.
Introduction
The jobs
command is a built-in shell command used to display the status of jobs that are currently running in the background or have been stopped. It's particularly useful for managing processes that you've started and then moved to the background using &
or suspended using Ctrl+Z
. Understanding jobs
allows you to effectively control and monitor the processes launched from your terminal.
Use Case and Examples
Listing Background Jobs
This command lists all background jobs with their job ID, status, and the command that was executed.Listing Jobs with Process IDs
This command lists jobs along with their process IDs (PIDs). Knowing the PID allows you to use other commands likekill
to manage these processes. Referencing a specific job
This command brings job number 1 to the foreground. You can usebg %1
to put it back in the background. Note that %1
refers to job ID 1, not process ID. Checking status with verbose output
This displays only process IDs (PIDs) of the background jobs. This is useful if you want to easily pipe these PIDs into another command.Commonly used flags
Flag | Description | Example |
---|---|---|
-l | Lists process IDs in addition to the normal information. | jobs -l |
-p | Lists only the process IDs of the background jobs. | jobs -p |
-n | Lists jobs whose status has changed since the last notification. | jobs -n |
-r | Restricts output to running jobs | jobs -r |
-s | Restricts output to stopped jobs | jobs -s |