1

Say there's a running process that produces output, but you don't know where that output is redirected (it might go to a file, an open terminal, or /dev/null for all I know). Is it possible to snoop on existing process's output stream possessing only the PID of that process? Perhaps some way through /proc?

2 Answers 2

3

You can use this command to see output of a running process:

tail -f /proc/$PID/fd/1
5
  • Does that aggregate all output? What if the process is outputting to multiple files? (interesting, +1) Commented Oct 9, 2013 at 19:32
  • This is for grabbing stdout/stderr only. Commented Oct 9, 2013 at 19:33
  • To redirect an already running process's stdout/stderr see: serverfault.com/questions/213119/… Commented Oct 9, 2013 at 19:34
  • 1
    This works only if the output is redirected to a file. It does not work if the descriptor points to a terminal /dev/pts/4, and I did not bother calling tail -f on descriptor that points to /dev/null Commented Oct 9, 2013 at 19:37
  • Check the link I provided. Using gdb you can redirect a running process's stdout/stderr to any other place you want. Commented Oct 9, 2013 at 19:42
0

Maybe you can try

lsof | grep $PID

Or

ps aux | grep $PID

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.