Wednesday, September 27, 2017

Ubuntu Keep Process Running After SSH is Terminated

Hello,

Recently I was learning NodeJS and for that I faced an issue with node server. I installed node server via SSH and started server. But as soon as I closed terminal Node server stopped working. But I needed server up and running even if terminal is closed. So after struggle of sometime I found out solution. Here is what we have to do.

Basically when you type command on SSH and start server it runs on the foreground and wait for process to be finished. So as soon as you close terminal foreground process is also terminated and hence your server is stopped.

So in this case you have to run server as background process and if you are using ubuntu you can use nohup  and & to start running process in background hence it will not be terminated once the terminal is closed.

So here is the command you have to follow.

$ nohup "COMMAND" &

Here COMMAND is your command to start the server and since you have mentioned nohup and & it will run the process in background and will not be terminated when SSH is closed.

No comments:

Post a Comment