[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

OT: What is the meaning of /proc/$PID/fd/* files?



Hello,

I am trying to figure out the meaning of:

	/proc/$PID/fd/*

files.

As:
- their name suggests
- as most of the descriptions on the web around indicate
- and consistently with wishful thinking
I thought that writing to /proc/$PID/0 would mean that designated process will receive the written date.

To verify this, I wrote a small program:

  -------------------------------------
  #include <unistd.h>

  char buf[10];

  int main()
  {
        unsigned u = read(0, buf, 10);
        write(1, buf, u);
        return 0;
  }
  -------------------------------------

ran it:

  ./main

and then if I tried something like this:

  echo "foo" > /proc/$PID/fd/0

the expectation were that the process would be able to read 4 bytes from its standard input.

  'f', 'o', 'o', '\n'

What actually happened was:
- "foo" string appeared on the appropriate terminal
- the "./main" process remained blocked in the "read" system call.

Is there somewhere a concise and correct description that explains this?


Reply to: