I understand file descriptor (or file handler) is an file IO technique in Linux systems.
I also know that each process has 3 standard streams (namely stdin, stdout and stderr) that are represented by files with descriptors from 0 to 3.
However, I notice that all the processes I examined with lsof -p <pid>
has an extra file descriptor 255
with read permission.
From this answer, I learned that this feature is specific to Bash shell, however both the answer the and the referenced source didn't really explain what this file descriptor is for.
My question:
- What is the 255 file descriptor for?
- Can I make use of it in my Bash script or is it just an internal working mechanism that is not supposed to be used/manipulated manually?
Best Answer
For the last part of your question:
can I use it?
From
man bash
:So, if you mean use as creating a new fd with that number the answer is no.
If you mean use as: "write to that fd":
Or to read from it:
the answer is yes.
But, probably, it should be better (independent of shell) to use
/dev/tty
to access thetty
.what is file descriptor 255 for?
As an alternative connection to the tty in case fd 1 (
/dev/stdout
) and fd 0 (/dev/stdin
) get blocked.More detail.
Other shells may use a different number (like 10 in zsh)
From mail list: