How to attach an already running process to a screen session

Happens to me all the time, I start something that takes too long, and I think “I wish i had started that in screen”… So here is a quick reference guide:

  1. Suspend the process with Ctrl+Z.
  2. Resume the process in the background with bg.
  3. Disown the process with disown %1.
  4. Launch a screen session with screen.
  5. Find the PID of the process using pgrep.
  6. Use reptyr to take over the process reptyr.

Original found on LinkedIn

Leave a Reply

Your email address will not be published.

%d bloggers like this: