Executing the command below to display the file descriptors owned by the current process shows 4 file descriptors. File descriptors 0, 1, and 2 are stdin, stdout and stderr. What is file descriptor 255?
ls /proc/$$/fd
Output:
0 1 2 255
In the Bash shell environment, every process has three files opened by default. These are standard input, display, and error. The file descriptors associated with them are 0 , 1 , and 2 respectively. In the Bash shell, we can assign the file descriptor to any input or output file. These are called file descriptors.
A file descriptor is an unsigned integer used by a process to identify an open file. The number of file descriptors available to a process is limited by the /OPEN_MAX control in the sys/limits. h file. The number of file descriptors is also controlled by the ulimit -n flag.
A file descriptor is a number that uniquely identifies an open file in a computer's operating system. It describes a data resource, and how that resource may be accessed. When a program asks to open a file — or another data resource, like a network socket — the kernel: Grants access.
The open files are 0 (stdin), 1 (stdout), and 2 (stderr). 255 is a little trick that bash uses to keep a copy of these for when they are redirected. This is specific to bash.
Source: https://books.google.com/books?id=wWjqCF9HLfYC&pg=PA231
Example:
echo foo 1>/dev/null 2>/dev/null >/proc/$$/fd/255
Output:
foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With