Sunday, January 22, 2012

The importance of nohup command while working through SSH clients

We use SSH client to connect to Linux servers and I had a few programs running in the server since 2 days. I was expecting that the process would complete in next 2 days or so. My machine was connected to 3 servers with dashboard like windows displaying the progress/status in each servers.

My machine hanged a few hours back, while installing Java. Java installer is never robust, unlike Java the language - my experience. Then I had no option but to restart. I had forgotten that my programs were running on the servers. A few hours after restarting my machine, I checked the status in the servers. All my processes were terminated the moment I god disconnected from the servers.

nohup arrived to rescue!

After that I stopped all the remaining threads from the servers by executing:
$ killall -g -u myusername
Then I learnt to use nohup to execute all the programs
$ nohup ./ &
The output are then redirected to nohup.out which can be viewed using
$ tail -f nohup.out

nohup enables the command to keep running even after the user who issues the command has logged out.

Thank god I got rescued and learnt it on time! Thank god!