Alternate title for this post is “The Handiest Freaking Linux Utility of the Day!”
Ever start a long-running process and then realize “oh crap, I am going to have to leave, but I don’t want to kill this process!” I have reached this point several times, frantically poring over the screen documentation, looking for a way to attach the process to a screen terminal. The short answer seems to be: ya can’t do it.
Enter Nelson Elhage, my new personal hero, for this simple reason: he created a tool called reptyr (re-’pty’-er). In Nelson’s words, “Just start a screen, use reptyr to grab it, kill the ssh session and head home.”
You can install this nifty tool with a few keystrokes:
git clone https://github.com/nelhage/reptyr
sudo make install
And then attach your process to a screen with a few more:
reptyr 12345 # 12345 being your process id