FUNDAMENTALS A Complete Guide for Beginners
The jobs command is one of the process control commands in Linux. This is a pretty plain command in Linux. The function of the jobs command is to show a rundown of all background and foreground processes that are initiated by the shell. In this section, you will learn the ins and outs of the jobs command in Linux.
A. Description
The jobs command is used to display a set of jobs that are currently running in the background & the foreground in Linux. If the command prompt does not show any information that means no jobs are running at that time. By using the jobs command, you can see the process ID, job number & status of each Job. This command can be effective to view or manage the jobs running in the background or foreground of the terminal.
B. Syntax
The jobs command in Linux has an easy syntax. And the syntax is as shown below:
jobs [OPTION]
C. Options
A few options are available for the jobs command. I have listed them here.
There is no man page for the jobs command. Although, you can explore the help page to know more about the jobs command.
help jobs
Useful Options
- -l, Displays the process ID, job number and status of each job
- -n, Displays only jobs that have changed status since the last notice.
- -p, Displays only the process ID of each job.
- -s, Displays the jobs that are stopped.
- -r, Displays the jobs that are running.
- -x, Executes command in the background.
Practical Examples of the “jobs” Command in Linux
The jobs command in Linux is very simple to use. Here you will learn some useful examples of the jobs command in Linux.
Example 1: View Running Jobs Using the “jobs” Command in Linux
To view the jobs running in the background and in the foreground, I am using the jobs command. To do the same you can follow the steps below:
Steps to Follow >
➊ At first open the Ubuntu Terminal.
➋ Type the following command in the command prompt:
jobs
➌ Now, press the ENTER button.
Output >
In the first image below, there is nothing on the terminal screen as no jobs are running currently in the background and foreground.But in the second image, the output shows that some jobs are running.
Similar Readings
- The “killall” Command in Linux [6+ Practical Examples]
- The “kill” Command in Linux [4+ Practical Examples]
- The “ps” Command in Linux [9+ Practical Examples]
Example 2: View the Process ID of Each Job Using the “jobs” Command in Linux
To view the process ID of each job running in the background and in the foreground, I am using the jobs command along with the option -p . To do the same you can follow the steps below:
Steps to Follow >
➊ At first launch the Ubuntu Terminal.
➋ Type the following command in the command prompt:
jobs -p
➌ Now, hit the ENTER button.
Output >
In the image below, the output displays the process ID of each job running.
Example 3: View the Process ID, Job Number & Status of Each Job
To view the process ID, job number & status of each job running in the background and in the foreground, I am using the jobs command in Linux along with the option -l. To do the same you can follow the steps below:
Steps to Follow >
➊ At first open the Ubuntu Terminal.
➋ Type the following command in the command prompt:
jobs -l
➌ Now, hit the ENTER button.
Output >
In the following image, the output displays the process ID, job number & status of each job running.
Example 4: View the Jobs Taken to the Background
To view the jobs that are taken to the background you can use the bg command in Linux.
Steps to Follow >
➊ Firstly launch the Terminal in Ubuntu.
➋ Type the following command in the command prompt:
bg %1
➌ Now, hit the ENTER key.
Output >
As you can see in the image, the output is displaying the job that is running in the background.
Example 5: View the Background Jobs Taken to the Foreground
To view the background jobs taken to the foreground you can use the fg command in Linux.
Steps to Follow >
➊ Firstly launch the Terminal in Ubuntu.
➋ Type the following command in the command prompt:
fg %1
➌ Then, press the ENTER key.
Output >
As you can see in the image below, the output is displaying the background job that is taken to the foreground.
Conclusion
As explained in this section, the jobs command has some uses in Linux. You’ve also found the syntax, some functional options, and the practical applications of this command. To become proficient in Linux, learn the command and its practical applications thoroughly.
Similar Readings