Bob's Notepad

Notes on projects I have done and things I have learned saved for my reference and for the world to share

Monday, June 17, 2024

Open a process that's already running in a terminal in a screen session

 It happens time and time again.... you start a process and then it starts taking a really long time and you need to leave and take your laptop with you.  After many years I have found a solution that worked -- well at least this one time.

First install reptyr:

  • Run "apt-get install reptyr"

Then in the running session:

  • Press ctrl-z
  • Run "bg" (no parameters should be needed)
  • Run "jobs -l" and look for the process ID of the stopped job
  • Run "disown -h processID"

In another terminal, launch screen and then:

  • Run "reptyr -T processID" (this may lock up your other terminal but we don't need it anymore)
  • You may have to press enter after a few moments to get back to a command prompt
  • Run "jobs -l" and you should see your process there now
  • Run "fg" and your process should now be running in your new screen session

It should be noted that the -T option of reptyr is experimental.  In some cases, depending on the task you are running, you may be able to just run "reptyr processID" in a screen session without backgrounding and disowning but many tasks spawn child processes and without the -T you will get an error in those instances.

 

Reference Link


0 Comments:

Post a Comment

<< Home