While using any operating system, there can be multiple processes running on it. These processes are mainly categorized as the background processes and the foreground processes. As the name says, a background process is one that runs silently in the background without requiring any human intervention. On the other hand, a foreground process is the one that we can actually see and interact with continuously. We can even send a process to the background or bring a process to the foreground as per our needs and to know how this can be done, you will have to go through this article.
Sending a Process to the Background in Linux
For sending a process to the background in Linux Mint 20, you can follow either of the two methods described below:
Method # 1: Using the “&” Symbol:
This is the simplest method of sending any desired process to the background in Linux Mint 20. All you have to do is to type the name of the desired process in your terminal followed by a space and the “&” symbol and then press the Enter key as shown below:
$ processName &
We wanted to run the Firefox process in the background which is why we have replaced “processName” with “firefox”.
When this command will be executed, the Firefox process will immediately start running in the background.
Method # 2: Using the “bg” Command:
For following this method, first, you will have to start that process which you want to run in the background through the terminal as follows:
We wanted to start the Firefox process which is why we have replaced “processName” with “firefox”.
As soon as you will execute this command, the Firefox browser will instantly launch as shown in the image below:
After doing that, you need to press Ctrl Z while staying at your terminal, and you will receive a “Stopped” message on the terminal as shown in the following image while you will still be able to see an active Firefox window on your screen.
Finally, you need to type the command shown below and then hit the Enter key:
This command will immediately send the specified process to the background while assigning it a job ID as shown in the following image:
For confirming if the specified process has been successfully pushed to the background or not, you can execute the command shown below:
Running this command will list down all the background jobs. You will be able to see your specified job within this list as shown in the following image:
Bringing a Process to the Foreground in Linux
A process that has been running in the background can easily be brought to the foreground by making use of its job ID as shown below:
$ fg %jobID
Since we wanted to bring the Firefox process to the foreground, that is why we have replaced “jobID” with “1”. The job ID can easily be found by running the “jobs” command in the terminal.
Executing the “fg” command will bring the specified process immediately to the foreground while displaying the message shown in the following image:
If you want to confirm whether the specified process has been brought to the foreground or not, you can simply run the “jobs” command again and you will not be able to find your specified job over there. In our case, since we did not have any processes running in the background other than Firefox, therefore, running the “jobs” command did not produce any output for us this time because we did not have any processes running in the background any longer.
This is how you can easily send any desired process to the background or bring it to the foreground by following this tutorial. In this way, you will be able to manage the working of these processes on your own.