How to run Command In Background on Linux:
A background process is the process which executes behind the scenes. Suppose you have a long-running task that you need to run, but you also want to get some other work done. Linux lets you start a task in the background and keep on doing other things from the command prompt. The most popular and frequently used are & and nohup. Including of these two options this tutorial will also describes you to use of screen command.
Adding & the end of the command
On Linux/Unix based systems you can put a task (such as command or script) in a background by appending a & at the end of the command line. In other words you can say that easily send any process in backgroud.
# command & # script-name &
# find / -name *.c > /root/output.txt &
Using & with nohup
You can use nohup command line-utility which allows to run command/process or shell script that can continue running in the background after you log out from a shell:
# nohup command-name &
# nohup find / -size +1k > /root/output.txt &
Screen is better option for long running processes. Using screen you can simply get the same session running on remote server even after logout from ssh. For this test you can do the following
Now start your process in background.
# find / -size +1k > /root/output.txt &
Let’s detach your screen session with keyboard shortcut CTRL+a+d or ctrl+alt+d. It will return you to command line. Now exit your ssh session and again connect system through ssh and execute following command to get old screen session running.
# screen -r
Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!