Awesome Linux Process Management

Mar 9
Posted by

I recently discovered a neat trick with linux processes that allow you to a) run them in the background and/or b) keep them running after you disconnect from SSH or your connection, however that may be.

Running processes in the background is quite common so if you’re familiar with linux then you’ll know that appending an & to the end of the command will throw it in the background out of view and allow you to keep working, while it runs.

The issue with this is that when you disconnect from SSH, that script will cease to run. The way you can prevent that is you can redirect output to the nohup command which will continue to run after closing your connection.

You can also combine the two to run it in the background AND keep running if you drop connection.

Now the neat thing about nohup is it stores any output from the command in ~/nohup.out and can be viewed using any method (tail, nano, etc). But what if you wanted to view the output in realtime as if you were viewing the command running? You can use the tail -f command to do so. This will load the last few lines of the file as well as print out any new lines that are posted to the file while the command is running.

So when I run my nodeJS server for example, I run it as follows so it’s in the background, keeps running if I drop connection, AND I load the log file into tail -f so I can view the output as normal. This prevents the server from stopping if I lose connection (like when I’m working from the bus :P) as well as any errors 😀

Yay for awesome process management in unix/linux!

Filed Under: Dev
Tagged With: , ,