Debian

How to Send Processes to the Background in Linux

How to Send Processes to the Background in Linux

Introduction

In this article, we are going to learn how to send processes to the background in Linux to free our terminal to get back control of our system. Many new sysadmins find it very difficult to accomplish multiple tasks once a process takes longer. This often happens on servers where multiple applications are deployed. I am using the Debian 10 Buster edition for this piece of the tutorial. All the commands and setup are valid for the rest of the Debian variants. It would still be better to check the documents of your installed distribution.

Why send a process to the background?

Our simple answer to this question will be to set the terminal free for the next command.

The complex answer is that whenever bad things happen, most of the time either using a desktop or a server instance, we have access to a terminal only. At that time, a user doesn’t want it to be occupied by one job. Thanks to Linux, we can free the terminal from sending a job to the background and keep running new commands to get back to our system.

Running a process

Running a process is as simple as running any other piece of software on Linux. I am going to run a trimage package for our learning purpose here. We’ll discuss trimage in a different tutorial in the future.

Let’s do it now:

$ trimage

As you can see that trimage is running without any issues but the terminal is now stuck.

Sending a trimage to the background is as simple as hitting Ctrl + Z and it will stop the trimage job for the time being.

The magic begins when you enter

$ bg

and hit enter.

Command bg will send the trimage process to the background. Trimage will keep running as usual whereas the terminal will be free to perform the next command.

If the package has a GUI, you can choose to close it from there, but if the package doesn’t have any GUI you can simply use

$ fg

command to push the process to the foreground as shown below:

Now close the process as always we do use Ctrl + C and you’ll return to a normal terminal.

Conclusion

For now, we have covered a significant amount of tips and tricks about sending processes to the background in Linux. As sky is the limit in Linux and if you have figured a different way to manipulate your Linux jobs then share with us in comments.

Have your say!

Similar Posts