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
Asked
Active
Viewed 94 times
1 Answers
11
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.
MikeyB
- 39,673
-
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.
watchon FreeBSD, but I'm not sure what the Linux/RedHat equivalent is, if one exists. – voretaq7 Feb 12 '14 at 20:17 -
1
-
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 '14 at 21:35
-
"I do not want to lose the output to the screen" <- I even got that for you. :D – MikeyB Feb 12 '14 at 21:41
screen,tmuxor the classic combination ofnohuping it and redirecting the output to a file. Plenty of answer about all of those on [su]. – Hennes Feb 12 '14 at 20:03