Software & Apps Linux 63 63 people found this article helpful Multitasking: Background Process and Foreground Process Manually control how shell processes execute by Juergen Haas Writer Former Lifewire writer Juergen Haas is a software developer, data scientist, and a fan of the Linux operating system. our editorial process Juergen Haas Updated on December 08, 2019 Linux Switching from Windows Tweet Share Email As a multitasking operating system, Linux supports the execution of many processes—basically, programs or commands or similar tasks—in the background while you continue to work in the foreground. Foreground Processes A foreground process is any command or task you run directly and wait for it to complete. Some foreground processes show some type of user interface that supports ongoing user interaction, whereas others execute a task and "freeze" the computer while it completes that task. From the shell, a foreground process begins by typing a command at the prompt. For example, to see a simple listing of the files in the active directory, type: ls You'll see the list of files. While the computer is preparing and printing that list, you cannot do anything else from the command prompt. After the list of files prints to standard output, you regain access to the shell prompt. Background Process Unlike with a foreground process, the shell does not have to wait for a background process to end before it can run more processes. Within the limit of the amount of memory available, you can enter many background commands one after another. To run a command as a background process, type the command and add a space and an ampersand to the end of the command. For example: command1 & When you issue a command with the concluding ampersand, the shell executes the work, but instead of making you wait for the command to finish, you'll immediately be returned to the shell. At this point, you can enter another command for either foreground or background process. Background jobs are run at a lower priority to the foreground jobs. You will see a message on the screen when a background process finishes. Switching Between Processes If a foreground process is taking too much time, stop it by pressing Ctrl+Z. A stopped job still exists, but its execution is suspended. To resume the job, but in the background, type bg to send the stopped job to background execution. To resume a suspended process in the foreground, type fg and that process will take over the active session. To see a list of all suspended processes, use the jobs command, or use the top command to show a list of the most CPU-intensive tasks so that you can suspend or stop them to free up system resources. To change the execution priority of a process, use nice and renice. Shell vs. GUI Multitasking works differently depending on whether you're working from the shell or a graphical user interface. Linux from the shell supports just one active foreground process per virtual terminal. However, from the practical perspective of the user, a windowed environment (e.g., Linux with a desktop, not from a text-based shell) supports several active windows that effectively serve as multiple simultaneous foreground processes. In practice, Linux behind-the-scenes adjusts the priority of processes in a GUI to promote system stability and support end-user processing.