How to send a process to background in Linux

In this article, we cover how to send a process to the background in Linux. We never think of running a process in the background while working through a Graphical User Interface (GUI). Therein, we can open multiple tabs/windows. And, select the tab/window that is required. Though it may feel that other tabs/windows are inactive or running in the background but that doesn’t happen.

But, when it comes to working with a text-based terminal, we don’t have to option to open tabs/windows. In that case, push the currently running process to the background. So that, we can begin with a new task.

There are two ways we cover here to send a process to the background in Linux:

  1. through ampersand (&) and,
  2. Ctrl + z and bg command.

Send a process to the background in Linux

Method I. Through ampersand (&):

Use an ampersand (&) at the end of the command in the terminal. For instance,

nano test-file &

This would return with a Process ID. Or, if we run:

sudo apt update &

Then, it would show us the output in the standard output. Here, pressing Ctrl + c won’t help because the process runs in the background. We assume that you have used sudo earlier. And, there is some time left before the password timeout happens.

Method II. Use a combination to run the process in the background: Ctrl + z and bg command:

We continue with the above example.

sudo apt update

Press Ctrl + z immediately. This would stop the process and send it to the background. We can verify it through the command:

jobs -l

Now, if we wish to continue with the process but want the process to run in the background. Then, use the command:

bg

You should see the relevant text in the standard output.

In conclusion, though there are other methods as well that can be used to send a process to the background in Linux. We prefer to use the above two.

Similar Posts