Linux Commands

How to Bring a Background Linux Process to The Foreground

A process is an instance of a running program. Any program you execute in a Linux shell spawns a new process that’s identifiable using a process name and a Unique Process ID. As a system administrator, you will need to be  familiar with the command for managing processes in a Linux system

This article will focus on job control commands, allowing you to send processes in the background and bringing background processes to the foreground.

How to Run a Linux Process in the Background

To run a process in the background in Linux, use the ampersand symbol &. For example, to start the calculator in the background:

$ gnome-calculator &

Executing the process in the background gives an output with two values. The first value, enclosed in square brackets, shows the Job ID, and the second value indicates the process ID.

How to Send Foreground Linux Processes to Background

We can also send a foreground process to the background using the CTRL + Z shortcut. This shortcut will suspend the process; then, you can use the command bg to send it to the background.

For example, let us start GParted in the foreground (this will prevent the shell from executing other commands until we terminate the process).

While the process is running, press CTRL + Z to suspend the process. That will return our shell prompt, enter the command bg, and this will send the process in the background as shown:

How To Show Background Processes

To show the processes in the background, use the jobs command.

$ jobs -l

The jobs -l command will show the Job ID, Process ID, process state, and the process name.

How to Send Background Processes to the Foreground

We can also bring a background process to the foreground using the fg command followed by the %[job id]

Let us start by listing the process in the background:

jobs -l

To bring a process such as GParted, with Job ID, 2 to the foreground, we use the command:

$ fg %2

As you can see from the command above, this brings the command to the foreground.

Conclusion

In this tutorial, we discussed how to manage jobs, send process to the background and bring background processes to the foreground.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list