murvinlai murvinlai - 4 months ago 39
Linux Question

How to run process as background and never die?

I connect to the linux server via putty SSH. I tried to run it as a background process like this:

$ node server.js &


However, after 2.5 hrs, the terminal becomes inactive and the process die. Is there anyway that I can keep the process alive even the terminal disconnected?

thanks.




Help, please!

Actually, I tried
nohup
but as soon as I close the Putty SSH terminal or unplug my internet, the server process stops right away.

Is there anything I have to do in Putty?




Update on 2012 FEB: There is a node.js module, forever. It will run nodejs server as daemon service.

Good. :)

MK. MK.
Answer

Simple solution (if you are not interested in coming back to the process, just want it to keep running):

nohup node server.js &

Powerful solution (allows you to reconnect to the process if it is interactive):

screen

Also consider the newer alternative to screen, tmux.