5

I want to capture stdout of running process whose stdout is being redirected to /dev/null. I tried using system call fcntl(), however the moment I close fd "1", it was being allocated for other files as it was lowest available fd number.

Any ideas how to lock given fd and reassign to other file?

3

I think you can capture that by using proc filesystem:

$ cat /proc/<PID>/fd/1

  • Can you add an example of how this works? – Bruce Ediger Jul 5 '13 at 17:27
  • 2
    $ cat /proc/<PID>/fd/1 works when written stdout to a file but doesn't work when stdout sent to /dev/null – Srihari Konakanchi Jul 5 '13 at 19:02
2

I believe you can use gdb to do that. See several of the answers to this stackoverflow question. Seems like that might come from this blog article.

  • right, I'm looking for the lines of code to execute while process connected to gdb – Srihari Konakanchi Jul 5 '13 at 19:03
0

You can do it using reredirect (https://github.com/jerome-pouiller/reredirect/).

reredirect -m /dev/null <PID>

You can restore initial output of your process later using something like:

reredirect -N -O <M> -E <N> <PID>

(<M> and <N> are provided by previous launch of reredirect).

reredirect README also explains how to redirect to another command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.