How can a process intercept stdout and stderr of another process on Linux?

前端 未结 8 599
离开以前
离开以前 2020-11-27 11:23

I have some scripts that ought to have stopped running but hang around forever. Is there some way I can figure out what they\'re writing to STDOUT and STDERR in a readable

8条回答
  •  执笔经年
    2020-11-27 11:49

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

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

    Via the man page for strace:

       -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 than you need (the hexadecimal part), but you can sed that out easily.

提交回复
热议问题