Sunday, October 28, 2012

[Tutorial] How to run processes over SSH (or linux) in background


If you are new to linux scene and SSH, you would have probably realized whenever you run a program over SSH and if you terminate the session, the program you ran also terminate as well.
This can be a problem if you would like to leave a server running.

Solution #1

Simplest solution would be to run the program in the background.
You can do that by running

 bg %1

Even if you terminate your SSH session, the program would still be running.

Solution #2

Another simple solution is to use nohup.
It is a POSIX command that ignores hangup signal so even if session is closed, the program would still be running. You can use nohup simply by calling the program with nohup.

 nohup your_app&

Simple solution would be nohup

Solution #3

More complicated and redundant solution would be screen.
Screen is a software that allows multiple virtual consoles to be accessed through single terminal.
You can detach the session so that it keeps running even when you close your terminal.

 screen -d -m bash

Last solution needs an update.

No comments: