A FileDescriptor file descriptor standard Input output error file descriptor

Source: Internet
Author: User
File Descriptor   when an application requests to open or manipulate a file, the operating system sets a list of files for the application, which is not described in detail here the operating system will provide you with a nonnegative integer, as an index number that acts like an address or pointer or offset . This index number is used to locate the location of the file data in memory. This concept is called a file descriptor in Unix-like systems, and Linux has everything considered to be files, such as files, directories, processes, network sockets, various hardware devices, and so on. This concept is called a handle under Windows, and the handle is an identifier for various objects under Windows, such as files, resources, menus, cursors, bitmaps, etc. Well, now you should be able to understand the meaning of the file descriptor.
file descriptor to file system (everything in the operating system is a file descriptor can use a file descriptor to describe any resource object as if it were in the Java language (everything in Java is a class, an instance of a class, Any class is described with an instance of the class object.

The concept of using filedescriptor to abstract file descriptors in Java Package java.io; for Fileinputstream/fileoutputstream/randomaccessfile, use handle to represent the underlying file handle for Serversocket/socket, use FD to represent the underlying file handle The invalid value of FD and handle for FileDescriptor is -1

look at the description of the API:
an instance of the file descriptor class is used as an opaque handle to some structure related to the underlying machine This structure represents another source or receiver of open files, open sockets, or bytes.   The application should not create its own file descriptor.  

In fact, that is, the file descriptor instance, is used to represent a pointer/index of the file. The operating system interacts with the application through this value Like your phone number, in many scenarios, he is equivalent to you, though, he is not you at all, For example, friends want to talk to you, someone entrusted you to do business, insurance company sales and so on, through the phone can locate you   and can you build a phone number yourself? Obviously not, it must be provided by the operator our file descriptors, too, applications should not create their own file descriptors His method of construction, can only create an invalid file descriptor
you should not create your own file descriptor, which can be directly understood as: this thing is the underlying implementation of the content, the operating system to pass to you Moreover, for some other operations of the file, the bottom-level implementation is still the operating system to This is equivalent to the operating system gives you a pointer, the key you need to service, to the operating system can, specifically how to play, you can not control, also can not control   to understand the file descriptor only need to understand, the abstract concept of the file is the operating system responsible for the management of maintenance applications are asking the operating system for help, and the JVM is an application no matter what the location is, it's a descriptor for the application . The operating system provides a consistent interface access path, which is through this descriptor What is behind the descriptor, the operating system masks these things The implementation of this, for the application programmer, it is not necessary to pay attention to what he really is a thing, the operating system to solve     three descriptors in FileDescriptor FileDescriptor built-in three file descriptors are in out err type is FileDescriptor This is a Java-level description the specific value is 0 1 2, which is the description of the operating system level   in Linux, each process starts with 3 files open (everything in Linux is a file): * Standard input 0 * Standard Output 1 * Standard error 2  
three descriptors, created by calling the private method Standardstream Create a filedescriptor and set his handle value the internal set (FD) is a local method To put it bluntly, the three file descriptors of the operating system for standard input/output/error are obtained by calling the local method
       
It is also clear in the comments that file descriptors are not normally used directly
By using system.in System.out System.err
  application of file descriptors in the system class
In-out err is final static in system
The standard input and output is shared, but Java is multithreaded Therefore, they must be specially handled, and the thread is strictly forbidden to use these special objects until the initialization of the system is complete. because these objects are static, the Java class loading mechanism will be initialized when the system class loads, which creates a pair of contradictions; To resolve this contradiction, system loading is to initialize them to NULL, plus after completion, by Initializesystemclass
  The definition section in the system in out err is all final static It is also clear in the comments that the Initializesystemclass will be called for partial initialization work    
initializesystemclass method and local setIn0 setOut0 setErr0
initializesystemclass method for this piece, the main is Using three file descriptors   created fileinputstream  and FileOutputStream for out and err are converted to PrintStream
So, The three specialized file descriptors do not generally use the
     
The application does not create a file descriptor, which is called by the system, which is the local method to manipulate the The application just gets, then uses, the so-called use, and ultimately still needs the help of the operating system is the data item that is required when an application operates a file when interacting with the operating system
   

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.