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.
The easiest solution
Ctrl + Zto suspend the processbgto resume the process in the backgrounddisown -ahto remove all jobs from the shell and make them ignore SIGHUPexitto close the terminal
Demo
For experimenting purposes, try the following:
terminal 1
bash -c "sleep 10" & disown -ah && exitOn a new terminal, you can see sleep is still in the process list. After 10 seconds it closes as expected:
terminal 2
ps aux | grep sleep