3 ms·
This technique also works for reopening stdout to a log file for a long-running service which was started w/ >/dev/null.
by falsedan 12y ago
This technique also works for reopening stdout to a log file for a long-running service which was started w/ >/dev/null.
- chx 12y agoPlease expand on this a little.
- falsedan 12y agoSure! after gdbing, call creat("/path/to/where/you/want/log") $1 = 3 call dup2(3,1) $2 = 1 call close(3) $3 = 0 Then start tailing /path/to/where/you/want/log
- davidu 12y agoThis is clever.
- gknoy 12y ago(Edit: Doh! Scooped by falsedan. His is shorter and probably more readable. :) In my defense, I tried it to make sure this works.) What I found via SO [0] was in the context of routing things to dev/null instead of stdout, but you appear to be able to route to whatever you need to: ;; Setup: A bash scropt printed 'wat' every second, ;; redirected to /dev/null ;; Attach to the process in question using gdb: gknoy$ sudo gdb 15488 ;; Use '1' as the open flag, for write-only (gdb) p dup2(open("/tmp/wat.log",1),1) $1 = 1 (gdb) detach Detaching from program: /bin/bash, process 15488 (gdb) quit gknoy$ cat /tmp/wat.log wat wat wat 0: http://stackoverflow.com/questions/593724/redirect-stderr-stdout-of-a-process-after-its-been-started-using-command-lin http://stackoverflow.com/questions/593724/redirect-stderr-st...
- deleted 12y ago[deleted]