How to make a process continue when you close an ssh connection

I have to backup tow drives on a remote Linux box. To do so I ran a rsync command, but there are almost 1Tb of small files. The process will take hours to complete and I can’t leave the terminal open for so long. Of course, can be any other situation that requires you to move a running program in the background and logout.

It’s a very easy thing to do, just follow these steps:

Press Ctrl + Z in your terminal window.  The system suspends the running program, displays a job number, and a “Stopped” message, and returns you to a bash prompt.

Type disown -h jobID in our case 1. The -h option is very important in our case because it marks the job so it ignores the SIGHUP signal (it will not be stopped by logging out).

The process now is in the background but is paused. Type bg 1 (1 is the jobID can by another number) to resume the running of the process in the background and a message is displayed confirming that.

[1]+  Stopped                 rsync -avhW /mnt/2 /mnt/usb8tb/hdd2/
$ disown -h %1
$ bg 1
[1]+ rsync -avhW /mnt/2 /mnt/usb8tb/hdd2/ &

Now you can logout without worries. 

Be the first to comment

Leave a Reply