Skip to content

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

jobs
This command lists all background jobs with their job ID, status, and the command that was executed.

Listing Jobs with Process IDs

jobs -l
This command lists jobs along with their process IDs (PIDs). Knowing the PID allows you to use other commands like kill to manage these processes.

Referencing a specific job

fg %1
This command brings job number 1 to the foreground. You can use bg %1 to put it back in the background. Note that %1 refers to job ID 1, not process ID.

Checking status with verbose output

jobs -p
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


Share on Share on

Comments