When a process is linked to a terminal, the process, as well as its child processes, will be terminated if the terminal is closed.
To solve this problem, the process has to be completely disconnected from its controlling terminal, i.e., run in the background.
If the process running in the background has to be moved to the foreground, use the fg command.
bg
command in LinuxIf an ongoing process has to be moved to the background, we can follow the steps below:
Ctrl + Z
to suspend the process.bg
command to resume the process in the background.&
symbolProcesses can be made to run in the background using the &
symbol at the end of the command.
For example:
sleep 100 &
jobs
commandThe jobs
command is used to list all the processes running in the background.
In the code below, we ran a sleep
command in the background using the &
symbol at the end of the command. Then, we list all the processes running in the background.
sleep 100 &echo "All background jobs:"jobs