Linux jobs command

The jobs command in Linux is used to display the status of jobs that are running in the background or suspended within the current shell session. It allows you to list and manage the background processes associated with the current shell session.

Here’s an overview of how to use the jobs command:

  1. Running a Background Job:
    To start a job in the background, you can use the & symbol at the end of a command. For example:
   sleep 60 &

This command runs the sleep command in the background for 60 seconds.

  1. Viewing Background Jobs:
    Once you have background jobs running, you can use the jobs command to view their status. Simply type jobs in your terminal, and it will display a list of background jobs associated with the current shell session. The output will include the job ID, status (running or suspended), and the command itself.
  2. Bringing Jobs to the Foreground:
    If you have a background job and want to bring it to the foreground, you can use the fg command followed by the job ID. For example:
   fg %1

This command brings the job with ID 1 to the foreground.

  1. Sending Jobs to the Background:
    To send a foreground job to the background, you can use the bg command followed by the job ID. For example:
   bg %1

This command sends the job with ID 1 to the background.

  1. Suspending Jobs:
    If you want to suspend a running job temporarily, you can use the Ctrl + Z keyboard shortcut. This will suspend the currently running foreground job and return control to the shell.
  2. Resuming Suspended Jobs:
    To resume a suspended job and bring it back to the foreground, you can use the fg command followed by the job ID. For example:
   fg %1

This command brings the suspended job with ID 1 back to the foreground.

These examples illustrate the basic usage of the jobs command and related commands for managing background jobs in Linux. It provides a convenient way to view and control background processes within your shell session.

Note that the jobs command only displays the background jobs associated with the current shell session. If you open multiple terminal windows or shells, each shell session will have its own set of background jobs.

For more information about the jobs command and its options, you can refer to the manual page by typing man jobs in your terminal.