Run a Program in the Background with nohup on Ubuntu Gnome 15.04

This is post is how to run a program from the terminal in the background so that it will continue to run even when the terminal window is closed. I use the nohup command to accomplish this. I have a server that I log into with ssh. I run a rysnc backup command to that copies data to a usb3, 2 GB external hard drive.  This can take several hours to complete. Sometimes I need to close my ssh session, for example to reboot my client computer, yet I don’t want the backup to stop. I am running linux, Ubuntu Gnome 15.04 and all commands are run from the terminal.

Example of no hup command

nohup nice -n20 bkup.offsite.cc.com.py > /dev/null 2>&1 &

I will break down what is happening.

nohup – prevents the commands following from stopping if the terminal window is closed

nice -n20 – runs the program bkup.offsite.cc.com.py at a lower priority for cpu resources to prevent other programs on the computer from slowing down

bkup.offsite.cc.com.py – the python backup program to execute

> /dev/null 2>&1 – This does not show error messages and output, nohup normally writes standard output to a file nohup.txt. When my output was written to nohup.txt, the file size was 1.2 GB!

& – puts the command in the background so that you can use the terminal for other tasks

To see the status of your running application run the following command:

jobs

Output will be:

[1]+  Running   nohup nice -n20 bkup.offsite.cc.com.py &

A good reference for working with jobs: http://linuxcommand.org/lc3_lts0100.php

Reference: http://unix.stackexchange.com/questions/32574/when-do-you-need-nohup-if-youre-already-forking-using?lq=1

Leave a Reply

Your email address will not be published. Required fields are marked *