How to attach an already running process to a screen session

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
cd reptyr
make
sudo make install

And then attach your process to a screen with a few more:

screen
reptyr 12345 # 12345 being your process id

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>