Friday, November 22, 2013

File Descriptor

In Unix like system File descriptor is abstract indicator for accessing file and are represented in integer value.  FD is a computer program term and highly used while programming in Unix like system using language like C, This is similar to file handle in windows like system.

By default operating system 3 file descriptor namely from 0-2. Where 0 represent standard input (stdin), 1 for standard output (stdout) and 2 for standard errors (stderr).


Operating system keeps index entry of opened files somewhere in Kernal’s address space which can be generally referred as file descriptor table. When a user process use open() or socket() (system calls to interface to the kernel) you are returned a file descriptor, which is an integer (These entries are represented by integers like ...100, 101, 102....)  And are maintains its file descriptor table in its address space. When a process want to access the file it passes the file descriptor to kernel with system call which in turns reads the file on behalf and returns the handle or result.

No comments:

Post a Comment