EvilZone
Programming and Scripting => C - C++ => : flowjob May 21, 2012, 08:55:01 PM
-
Ok,I'm quite new to C,and for fun and training I want to make something that catches stderr and prints it to the screen,but I don't know how I can attach to a process to be able to read it's stdin/stderr...
So my question is,how can I attach to a process and read its stderr in C?
-
Look for pipes.
I have not read it all, but I suppose you could do it like this
http://jineshkj.wordpress.com/2006/12/22/how-to-capture-stdin-stdout-and-stderr-of-child-program/
-
It's quite helpful about the howto in general :) ,but doesn't really solves my problem,because...
1. I only want to catch stderr
2. I want to attach to a existing process instead of creating a new one...
-
Attaching is more complicated. Look for ptrace. Try to hook write() syscalls which have '2' as file descriptor.
http://www.linuxjournal.com/article/6100
You could also code a dynamic library and override write calls, using the LD_PRELOAD env. variable.
http://scaryreasoner.wordpress.com/2007/11/17/using-ld_preload-libraries-and-glibc-backtrace-function-for-debugging/
-
So I've to do something like debugging the process I want to attach to?