Advertisement
iarmin

Redirect descriptor of a running process

Oct 29th, 2011
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. Firstly find the PID of the process:
  2. $ ps aux|grep cat
  3. rjc 6760 0.0 0.0 1580 376 pts/5 S+ 15:31 0:00 cat
  4.  
  5. Now check the file handles it has open:
  6. $ ls -l /proc/6760/fd
  7. total 3
  8. lrwx—— 1 rjc rjc 64 Feb 27 15:32 0 -> /dev/pts/5
  9. l-wx—— 1 rjc rjc 64 Feb 27 15:32 1 -> /tmp/foo1
  10. lrwx—— 1 rjc rjc 64 Feb 27 15:32 2 -> /dev/pts/5
  11.  
  12. Now run GDB:
  13. $ gdb -p 6760 /bin/cat
  14. GNU gdb 6.4.90-debian
  15. Copyright (C) 2006 Free Software Foundation, Inc
  16. [lots more license stuff snipped]
  17. Attaching to program: /bin/cat, process 6760
  18. [snip other stuff that's not interesting now]
  19. (gdb) p close(1)
  20. $1 = 0
  21. (gdb) p creat(“/tmp/foo3″, 0600)
  22. $2 = 1
  23. (gdb) q
  24. The program is running. Quit anyway (and detach it)? (y or n) y
  25. Detaching from program: /bin/cat, process 6760
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement