We’ve all experienced it: you’ve SSH-ed into a server and started a long-running task. Unexpectedly, it’s taking much longer than anticipated, and now you can’t close your laptop without interrupting the process. Fortunately, there’s a simple solution to close the terminal window without killing the ongoing task.
Quick and Easy Method
Follow these steps to keep your process running even after closing the terminal:
- Press
Ctrl + Z
to suspend the current process - Type
bg
and press Enter to resume the process in the background - Execute
disown -ah
to remove all jobs from the shell and make them ignore SIGHUP - Type
exit
to safely close the terminal
Demonstration
To experiment with this technique, try the following:
In Terminal 1:
bash -c "sleep 10" & disown -ah && exit
Open a new terminal (Terminal 2) and check if the process is still running:
ps aux | grep sleep
You’ll see that sleep
is still in the process list. After 10 seconds, it will complete as expected.
This method allows you to maintain server processes even when disconnecting from SSH, ensuring your long-running tasks continue uninterrupted.