From: Geoff Clare on
Seebs wrote:

> On 2010-06-09, Alan Curry <pacman(a)kosh.dhis.org> wrote:
>> No, /proc/self/fd is the properly documented, intentionally exposed
>> kernel-to-user interface. The /dev/fd symlink is sort of a joke that
>> unfortunately caught on.
>
>> "real unixy" /dev/fd has different semantics.
>
> Does it?

On Linux, opening /dev/fd/N has the same semantics as calling open()
with a pathname for the file that is open on /dev/fd/N. On
SVR4-derived systems opening /dev/fd/N has the same semantics as
calling dup(N).

This results in a lot of differences in the behaviour of the
new file descriptor. For example:

Linux
$ { read x; cat /dev/fd/0; } << EOF
> one
> two
> EOF
one
two

Solaris
$ { read x; cat /dev/fd/0; } << EOF
> one
> two
> EOF
two

Linux
$ exec 3< /dev/fd/1
$ echo foo >&3
-bash: echo: write error: Bad file descriptor

Solaris
$ exec 3< /dev/fd/1
$ echo foo >&3
foo

--
Geoff Clare <netnews(a)gclare.org.uk>