Run Command In Background on Linux
A background process is the process which executes behind the scenes. These processes run without user intervention. There are various way to do it for example using & or nohup or screen command. The most popular and frequently used are & and nohup(nohup is a POSIX command to ignore the HUP (hangup) signal). Including of these two options this tutorial will also describes you to use of screen command.
1. Using &
On Linux/Unix based systems we can easily send any process in background by appending & in command.
$ ls -l & $ tar czf temp.tar.gz /tmp &
In this way if you start a command in background and exited from shell, then shell will kill this background process with SIGHUP signal.
2. Using nohup
To prevent termination of background processes after shell termination use nohup command. nohup command simply use at prefix of command like. All the output generated with commands will save in nohup.out file in current directory.
$ nohup tar czf temp.tar.gz /tmp &
3. Using Screen
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
$ screen
Now start your process in background.
$ tar czf temp.tar.gz /tmp &
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
www.hackthesec.co.in
www.twitter.com/hackthesecurity
0 comments:
Post a Comment