code_junkie

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

Nov 12th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. tail -f /proc/(pid)/fd/1
  2.  
  3. import time
  4.  
  5. while True:
  6. print 'test'
  7. time.sleep(1)
  8.  
  9. python test.py
  10.  
  11. ps auxw | grep test.py
  12.  
  13. gdb -p (pid)
  14.  
  15. (gdb) call creat("/tmp/stdout", 0600)
  16. $1 = 3
  17. (gdb) call dup2(3, 1)
  18. $2 = 1
  19.  
  20. -e write=set
  21. Perform a full hexadecimal and ASCII dump of all the
  22. data written to file descriptors listed in the spec-
  23. ified set. For example, to see all output activity
  24. on file descriptors 3 and 5 use -e write=3,5. Note
  25. that this is independent from the normal tracing of
  26. the write(2) system call which is controlled by the
  27. option -e trace=write.
Add Comment
Please, Sign In to add comment