0

I was referring to this question to see if it is possible to spy on another running process' stdout. One answer suggests using tail -f /proc/<PID>/fd/1 to do so. So I opened two terminal sessions to try it. In the first terminal, I echoed the PID using echo $$. In the second terminal, I executed the tail command (without root privileges). I then noticed that there is significant hangup in the first terminal's IO (typing into the shell was disrupted and there was significant key delay). Why does this happen?

I'm running Ubuntu 18.04.

WalksB
  • 145
  • I'm more interested in knowing why typing is disrupted in the other terminal, not why the tail command didn't work as I wanted it to. – WalksB Jun 06 '20 at 01:37

1 Answers1

1

Running strace tail -f /proc/<PID>/fd/1 provides a clue.

The last line of the output will show that the tail command is waiting to read from the process.

read(3,

As you type into the original process, some of the characters will show up in that process and some will show up in the output of strace command. For example, typing "1234" in the original process may show 24 in the original process and the following lines in the strace output:

read(3, "1", 8192) = 1
read(3, "3", 8192) = 1

Although not apparent when running tail without strace, the tail command competes with the original process for access to what is typed.

Craig
  • 11