Re: Bug or feature? No EOF on /proc/xxx/fd/x

Snow Cat (snowcat@math.csufresno.edu)
Tue, 13 Feb 1996 23:53:51 -0800 (PST)


Martin Buck once wrote:
>
> Hi folks,
>
> I noticed a strange behaviour with Linux 1.3.57 (didn't try newer kernels,
> though): When reading from /proc/xxx/fd/x, the reading process doesn't get
> EOF even if the process you read from exits. This can be easily reproduced
> with these commands (using bash and typing fast enough :-) :
>
> $ sleep 30 &
> $ pid=$!
> $ cat /proc/$pid/fd/1
>
> cat will never exit even if sleep terminates. This worked with some older
> kernels (definitely with 1.2.13). It breaks some nice things like bash's
> process substitution (if you have a symlink from /dev/fd to /proc/self/fd).
>
> Any comments?
>

It's a feature in the sense that it allows one to use /proc/pid/fd/x for
file descriptor passing. Process A can make sure process B finished open()ing
a descriptor and than just exit. This descriptor can be, for example, a socket
bound to priviliged port that process B wouldn't be able to open by itself.

-- 
     Snow ^oo^ Cat <snowcat@math.CSUFresno.EDU>
      _  ->  <-    aka Oleg Kibirev <oleg@math.CSUFresno.EDU>
  ___(_)  _ _)_    
 /            _)   finger oleg@math.math.CSUFresno.EDU for PGP public key
 \_.-._
       |___/	Purr!