Hello,

I was looking at open file descriptors of /bin/sh
under procfs:

$ ls -li /proc/$$/fd/
total 0
      5 crw--w----  1 jschauma  tty    5, 1 Sep 14 02:47 0
      5 crw--w----  1 jschauma  tty    5, 1 Sep 14 02:47 1
1090579 crw-rw-rw-  1 root      wheel  1, 0 Sep 14 02:19 12
      5 crw--w----  1 jschauma  tty    5, 1 Sep 14 02:47 2
$ ls -li /dev/tty
1090579 crw-rw-rw-  1 root  wheel  1, 0 Sep 14 02:47 /dev/tty
$ 

0, 1, and 2 are obvious, but fd 12 did not seem
obvious to me.

Descriptor 12 being open to the current terminal means
I can do this:

$ echo foo >&12
foo
$ 

But I can also:

$ echo foo >&13
foo
$

even though fd 13 did not show up under /proc/$$/fd/.

Where does that fd come from, and why is not shown
under /proc/$$/fd?  And what's the purpose of fds 12
and 13?


When using /bin/ksh, I see a different extraneous fd,
fd 10, but I can't write to it:

$ ls -li /proc/$$/fd/
total 0
      5 crw--w----  1 jschauma  tty    5, 1 Sep 14 02:52 0
      5 crw--w----  1 jschauma  tty    5, 1 Sep 14 02:52 1
1090579 crw-rw-rw-  1 root      wheel  1, 0 Sep 14 02:51 10
      5 crw--w----  1 jschauma  tty    5, 1 Sep 14 02:52 2
$ echo foo >&10
/bin/ksh: >&10 : illegal file descriptor name
$ 

bash creates /proc/$$/fd/255 with inode 5, it seems...

Is this documented anywhere?

-Jan

Reply via email to