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 + Z
to suspend the processbg
to resume the process in the backgrounddisown -ah
to remove all jobs from the shell and make them ignore SIGHUPexit
to close the terminal
Demo
For experimenting purposes, try the following:
terminal 1
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:
terminal 2
ps aux | grep sleep