Saturday, December 17, 2011

File Descriptors

Discuss File Descriptors and its features

2 comments:

  1. A file descriptor is an index for an entry in a kernel-resident data structure containing the details of all open files

    In Unix-like systems, file descriptors can refer to files, directories, block or character devices (also called "special files"), sockets, FIFOs (also called named pipes), or unnamed pipes

    When a program opens a file, the operating system returns a corresponding file descriptor that the program refers to in order to process the file. A file descriptor is a low positive integer. The first three file descriptors (0,1, and 2,) are associated with the standard input (stdin), the standard output (stdout), and the standard error (stderr), respectively. Thus, the function scanf() uses stdin and the function printf() uses stdout. You can override the default setting and re-direct the process's I/O to different files by using different file descriptors:


    #include < cstdio >
    fprintf(stdout, "writing to stdout"); //write to stdout instead of a physical file


    References:
    http://en.wikipedia.org/wiki/File_descriptor

    ReplyDelete
  2. a file descriptor is an index for an entry in a kernel-resident data structure containing the details of all open files. In POSIX this data structure is called a file descriptor table, and each process has its own file descriptor table.

    NOTE ----The user application PASSES THE ABSTRACT KEY to the kernel through a system call, and the kernel will access the file on behalf of the application, based on the key. The application itself cannot read or write the file descriptor table directly.

    In Unix-like systems, file descriptors can refer to files, directories, block or character devices (also called "special files"), sockets, FIFOs (also called named pipes), or unnamed pipes.

    ReplyDelete