Skip to content

jobs MacOS Command Guide

The MacOS ‘jobs’ command is a built-in utility that allows users to manage background jobs. This command displays a list of all current jobs running in the background of your terminal session. By using this command, you can view the job ID, status, and the command that started the job. It is especially useful when you have multiple processes running simultaneously and need to keep track of them. Additionally, you can use the ‘jobs’ command to bring background jobs to the foreground, suspend jobs, or terminate them. This guide will walk you through the basics of using the ‘jobs’ command effectively on your MacOS system.

jobs Syntax:

Terminal window
jobs [options]

Options:

OptionDescription
-lDisplay process ID and status for each job.
-pDisplay process group IDs only.
-rDisplay only running jobs.
-sDisplay only stopped jobs.

Parameters:

ParameterDescription
None

jobs Command Samples:

View Current Jobs

Terminal window
jobs

Displays a list of current jobs running in the background.

Run a Command in the Background

Terminal window
sleep 10 &

Runs the “sleep 10” command in the background for 10 seconds.

Bring a Job to the Foreground

Terminal window
fg 1

Brings job number 1 to the foreground.

Send a Job to the Background

Terminal window
bg 2

Sends job number 2 to the background.

Kill a Job by Job ID

Terminal window
kill %1

Terminates the job with job ID 1.

List Stopped or Background Jobs

Terminal window
jobs -l

Lists all jobs, including their PIDs and statuses.

Suspend a Job

Terminal window
kill -STOP %1

Suspends the job with job ID 1.

jobs FAQ:

How do I use jobs in MacOS?

To use the jobs command in MacOS, execute the following command:

Terminal window
jobs

How can I list all active jobs in MacOS?

To list all active jobs in MacOS, use the following command:

Terminal window
jobs -l

Is there a way to display PID along with jobs in MacOS?

Yes, you can display the PID along with jobs in MacOS using the following command:

Terminal window
jobs -p

How can I bring a background job to the foreground in MacOS?

To bring a background job to the foreground in MacOS, you can use the following command:

Terminal window
fg %<job_number>

Can I stop a background job in MacOS using the jobs command?

Yes, you can stop a background job in MacOS using the jobs command. Here is an example:

Terminal window
kill -STOP %<job_number>

How do I resume a stopped job in MacOS?

To resume a stopped job in MacOS, use the following command:

Terminal window
kill -CONT %<job_number>

Applications of the jobs command

  • View a list of all currently active jobs in the shell
  • Manage multiple processes running in the background
  • Check the status of background jobs
  • Bring background jobs to the foreground
  • Terminate or suspend specific background jobs