We’ve all been there. You’ve SSH-ed into a server and started running some long running task.
But you didn’t expected it would start taking that long… And now you can’t close your laptop and stop the task midway.
The bellow steps allow you to close the terminal window, without killing the process.
Ctrl + Zto suspend the process
bgto resume the process in the background
disown -ahto remove all jobs from the shell and make them ignore SIGHUP
exitto close the terminal
For experimenting purposes, try the following:
bash -c "sleep 10" & disown -ah && exit
On a new terminal, you can see
sleep is still in the process list. After 10 seconds it closes as expected:
ps aux | grep sleep