MyTetra Share
Делитесь знаниями!
How can a process intercept stdout and stderr of another process on Linux?
Время создания: 24.11.2014 15:47
Раздел: root - Linux
Запись: Yurons/mytetra/master/base/1416833276ulty8tkqkn/text.html на

Now, attach gdb:

gdb -p (pid)

and do the fd magic:

(gdb) call creat("/tmp/stdout", 0600)
$1 = 3
(gdb) call dup2(3, 1)
$2 = 1

Now you can tail /tmp/stdout and see the output that used to go to stdout.

Gdb method seems better, but you can do this with strace, too:

strace -p -e write=1 -s 1024 -o file

   -e write=set
               Perform a full hexadecimal and ASCII dump of all the
               data written to file descriptors listed in the spec-
               ified  set.  For example, to see all output activity
               on file descriptors 3 and 5 use -e write=3,5.   Note
               that  this is independent from the normal tracing of
               the write(2) system call which is controlled by  the
               option -e trace=write.

This prints out somewhat more thanyou need (the hexadecimal part), but you can sed that out easily.

I used strace and de-coded the hex output to clear text:

sudo strace -f -e trace=write -e verbose=none -e write=1,2 -q -p $PID -o "| grep '^ |' | cut -c11-60 | sed -e 's/ //g' | xxd -r -p"

I combined this command from other answers.

Так же в этом разделе:
MyTetra Share v.0.60
Яндекс индекс цитирования