Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of file descriptor 255 in bash process

Tags:

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
like image 827
Aman Jain Avatar asked Apr 19 '15 12:04

Aman Jain


People also ask

What is a file descriptor in bash?

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.

What is file descriptor used for?

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.

What is the use of file descriptor in Linux?

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.


1 Answers

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
like image 191
Cyrus Avatar answered Sep 23 '22 13:09

Cyrus