4 ms·
Why ptrace? Why not just take a peek from the stdout/stderr streams in /proc/$pid/fd?
by mistaken 11y ago
Why ptrace? Why not just take a peek from the stdout/stderr streams in /proc/$pid/fd?
- d23 11y agoI've tried this approach and haven't been successful. Mostly I just wanted to try ptrace. I got as far as trying to read the file descriptors and getting nothing back. I'd love to hear how to do it this way though, since it would probably be a lot more robust and performant. My email is in `setup.py` in the repo if you want to reach out.
- mistaken 11y agoFair enough. Simply reading from the file descriptor won't work since some of the output will be redirected to the original process depending on who reads the next character first. The solution is to attach to the process using ptrace and then reditrect the stdout using dup. There is an example on how to do this with gdb on stackoverflow (http://stackoverflow.com/questions/1323956/how-to-redirect-output-of-an-already-running-process http://stackoverflow.com/questions/1323956/how-to-redirect-o...) This would give a nice performance boost if you could implement this in your code.