On multiple occasions, we have accessed a server via ssh and launched a command that we expected to finish soon, but for some reason, it has been prolonged and we fear that the ssh connection will be interrupted. It is at that moment when we think, why didn’t I launch it in a screen?
Don’t worry, in this article, I will explain how it is possible to leave a job in the background and then recover it from a screen session.
The steps are very simple:
- Start the process
- Leave it in the background: Ctrl+Z
- Disassociate it: disown PID
- Start screen
- Recover the process: reptyr PID
- Detach: Ctrl+a+d
That’s it, now we can leave the job in the session and check the result the next day ;)