Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My office job routinely sees me connected to a Linux box via VNC.

Sometimes I start a remote job on the console, and realize later that it runs much longer than expected. (Should have started that one under Screen in the first place...)

I don't want to keep my workstation running overnight just to keep the VNC session open; I would like to move that already-running remote job into a Screen session (on the remote box), so I can power down the workstation (and reconnect next morning).

How can this be done, if at all?

share|improve this question
2  
and it's a dupe, serverfault.com/questions/49877/… - seems it can't be done. –  Paul Dixon Aug 18 '09 at 11:08
    
add comment

migrated from stackoverflow.com Aug 19 '09 at 1:47

This question came from our site for professional and enthusiast programmers.

4 Answers

up vote 48 down vote accepted

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
add comment

Better working, yet more sophisticated, methods were researched in Moving a process to another terminal blogpost.

share|improve this answer
2  
Please refer contents of your links at least briefly. It's rather common that after a few years links are broken. This one is still fine, though. –  Olli Jun 10 '13 at 14:03
add comment

You cannot do this, easily. I'd suggest making it a habit to start screen as the first thing you do after opening a console.

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 you'd do disown -h %<jobid>. After that, you can safely close the terminal and the job will continue running.

share|improve this answer
    
This worked very well for my case. reptyr and retty both failed to grab the process, but all I needed was to be able to close a terminal and leave the process to run. –  STW Dec 28 '13 at 0:36
add comment

As you're using Linux, what about using retty inside the newly launched screen process?

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

HTH

cheers,

share|improve this answer
5  
That is a terrible hack, and I salute you for it. –  caf Aug 18 '09 at 12:44
    
Didn't know of retty, thanks. However, for the kind of long-running jobs I have in mind, I'm a bit reluctant to use a tool that refers to itself as "very lightly tested". I go with earl's solution. –  DevSolar Aug 18 '09 at 13:08
add comment

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.