How to run Linux processes in background
Learn all the steps to run a command in background, list background processes and bring them to foregound.
Table of Contents
- Run a command in background
- List background processes
- Attach to a background process
- Stop/resume a process
- Move a running process to background (detach)
Run a command in background
Some commands have specific parameters to run them in background, but the global parameter to run a process in background is
&. You need to add it at the end of the command.
$ wget https://example.com/file.txt &  40256
- The output means this process has the job 1 and PID (Process ID) 40256.
- It will show the standard output and standard error of the process in the terminal. If you don’t want this, redirect output and error to
some_command > /dev/null 2>&1.
List background processes
jobs -l (
-l includes the PID of the job).
$ jobs + Running wget https://example.com/file.txt &
Attach to a background process
You can move a background process to foreground with
fg [%<job number>] fg %1
%<job number>is optional if there is only one job.
Stop/resume a process
You can stop a foreground process with Ctrl + Z. To stop a background process, you can run
kill with the signal 19 (SIGSTOP):
kill -19 <process ID> # kill -s SIGSTOP <process ID>
To resume a stopped process, use
fg or use
kill with the signal 18 (SIGCONT):
kill -18 <process ID> # kill -s SIGCONT <process ID>
Move a running process to background (detach)
- Type Ctrl + Z to stop the process.
+ Stopped wget https://example.com/file.txt
- It shows the job number.
bgwith the job number.
$ bg 1 + wget https://example.com/file.txt ...
In Debian/Ubuntu systems, you can use
dpkg-reconfigureto reconfigure an installed package using intuitive dialogs. I will show you how to use this command to change some system settings.
If you have a scanned PDF and you want to be able to search and copy text from it, in this tutorial I will show you how to do it.
If you want to do X11 forwarding from your container to your host, you can type these simple commands.
If you don’t have a Graphical User Interface (GUI) on your Linux device, or you need a simple text-based web browser, I will show you a couple of great programs.
A comprehensive list of Linux-related websites sorted by categories.