How to Run and Control Background Processes on Linux

A shell environment on a Linux computer.
Fatmawati Achmad Zaenuri/Shutterstock.com

Use the Bash shell in Linux to manage foreground and background processes. You can use Bash’s job control functions and signals to give you more flexibility in how you run commands. We show you how.

All About Processes

Whenever a program is executed in a Linux or Unix-like operating system, a process is started. “Process” is the name for the internal representation of the executing program in the computer’s memory.  There is a process for every active program. In fact, there is a process for nearly everything that is running on your computer. That includes the components of your graphical desktop environment (GDE) such as GNOME or KDE, and system daemons that are launched at start-up.

Why nearly everything that is running? Well, Bash built-ins such as cd, pwd, and alias do not need to have a process launched (or “spawned”) when they are run. Bash executes these commands within the instance of the Bash shell that is running in your terminal window. These commands are fast precisely because they don’t need to have a process launched for them to execute. (You can type help in a terminal window to see the list of Bash built-ins.)

Processes can be running in the foreground, in which case they take over your terminal until they have completed, or they can be run in the background. Processes that run in the background don’t dominate the terminal window and you can continue to work in it. Or at least, they don’t dominate the terminal window if they don’t generate screen output.

A Messy Example

We’ll start a simple ping trace running. We’re going to ping the How-To Geek domain. This will execute as a foreground process.

ping www.howtogeek.com

ping www.howtogeek.com in a terminal window

We get the expected results, scrolling down the terminal window. We can’t do anything else in the terminal window while ping is running. To terminate the command hit Ctrl+C.

Ctrl+C

ping trace output in a terminal window

The visible effect of the Ctrl+C is highlighted in the screenshot. ping gives a short summary and then stops.

Read the remaining 47 paragraphs


0 Response to How to Run and Control Background Processes on Linux

Post a Comment