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.

I am running a process which will take several hours. I would like to disconnect from the server, but I do not want to lose the output to the screen. Is there a way to bring the process back to my screen after I disconnect? It's a Python script that is running, and it is on Red Hat 6.3

share|improve this question
    
You can do that with screen, tmux or the classic combination of nohuping it and redirecting the output to a file. Plenty of answer about all of those on Super User. –  Hennes Feb 12 at 20:03
    
Any feedback as to why my question was downvoted? –  Sugitime Feb 12 at 20:03
3  
Not my downvote, but I am guessing insufficient research. –  Hennes Feb 12 at 20:04
    
Nor my downvote...but just googling your own title to your question the first 2 results are StackExchange sites with the answer: google.com/search?q=Bring+process+to+screen –  TheCleaner Feb 12 at 20:05
    
None of the answer I found speak to how to pull a background process to screen if you didnt use the screen command when launching the command. –  Sugitime Feb 12 at 20:07

1 Answer 1

up vote 11 down vote accepted

Go back in time and smack yourself for not thinking ahead.

Then, fire up gdb against the running program, break into it and re-open STDOUT against a file. Then you should be able to background and nohup it without losing output.

(gdb) attach 18456
Attaching to process 18456
...
(gdb) call open("/tmp/myoutput.txt", 0102)
$1 = 3
(gdb) call dup2(3,1)
$2 = 1
(gdb) call close(3)
$3 = 0
(gdb) detach 
Detaching from program: /usr/bin/python2.7, process 18456
(gdb) quit

Then you can Ctrl-Z, bg, and disown the original process.

share|improve this answer
2  
@Sugitime All of the answers you found implicitly answer your question ("You can't go back in time." - usually). This answer offers you one option, and there are some OS-specific tricks you can do to attach to a different TTY (e.g. watch on FreeBSD, but I'm not sure what the Linux/RedHat equivalent is, if one exists. –  voretaq7 Feb 12 at 20:17
1  
You can't go back in time, but you can rewrite history. :D –  MikeyB Feb 12 at 20:41
    
That works for me. The answer is you can't do what I want to do, but I can restart the script and do what I want to do if I start it a certain way. Thanks guys. –  Sugitime Feb 12 at 21:35
    
"I do not want to lose the output to the screen" <- I even got that for you. :D –  MikeyB Feb 12 at 21:41

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.