Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sometimes I forget to run a program under a screen session and can't stop it in the middle, and I know it's going to take long.

Is there a way to screen an already running process without restarting it?

share|improve this question

3 Answers 3

Found this answer on serverfault from earl:

However, for your actual problem, there's another thing you could try: after having launched your job from the terminal, background it by typing ctrl-z and then bg.
After that, detach the job from it's parent shell - in bash: disown -h %<jobid>. After that, you can safely close the terminal and the job will continue running.

And this one from the same question from Rob Wells:

$ screen -S my_process
$ retty $(pgrep my_process)
/redraw

share|improve this answer
    
Is there any way to get the job to foreground again? 'screen' then 'fg 1' doesn't work for me –  Putnik Oct 4 '13 at 20:35
    
@Putnik - did you do the other steps as described? –  warren Oct 4 '13 at 20:37
up vote 7 down vote accepted

Found a duplicate In ServerFault.

Another solution not found in that post is using retty after starting a screen session.

share|improve this answer
5  
I deleted my answer; you can (and should) accept your own answer after 2 days. Feel free to quote the relevant parts here, as cross-site "duplicates" really aren't dupes due to the different audiences. –  Jeff Atwood Aug 24 '09 at 8:30
    
Accepted my own answer as per Jeff's request. –  LiraNuna Aug 26 '09 at 6:18
4  
But you didn't quote the relevant parts, as per Jeff's suggestion. =) –  David Thomas Sep 27 '09 at 22:04

Have a look at reptyr, which does exactly that. The github page has all the information.

reptyr - A tool for "re-ptying"

programs.

reptyr is a utility for taking an existing running program and attaching it to a new terminal. Started a long-running process over ssh, but have to leave and don't want to interrupt it? Just start a screen, use reptyr to grab it, and then kill the ssh session and head on home.

USAGE

reptyr PID

"reptyr PID" will grab the process with id PID and attach it to your current terminal.

After attaching, the process will take input from and write output to the new terminal, including ^C and ^Z. (Unfortunately, if you background it, you will still have to run "bg" or "fg" in the old terminal. This is likely impossible to fix in a reasonable way without patching your shell.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.