Advanced Unix Programming Environment study summary (a)

This series of blog is doing a summary of the contents of Unix for high-level programming environment for the interview he is frequently asked, or perhaps asked questions.

Unix architecture:

The core environment is the kernel, the system call interface is called, the establishment of public libraries in the system call interface only, the application can use the system call, you can also use the public library. Shell is a special application that provides an interface to run other programs.

Shell there are many, the most commonly used is the / bin / sh following Shell.

input Output:

File descriptors: usually a small non-negative integer, the kernel file that identifies a particular process is accessible, open a file or create a file when the file descriptor will be returned.

Standard input, output, error: whenever a new program is running, Shell will open its three file descriptors, responsible for input, output, and error. The three descriptors are linked to the terminal. May be used> <like redirection symbol stream.

Unbuffered IO: function open, read, write, lseek, close IO provides unbuffered, will write the details later.

Standard IO: common Printf, getc, putc.

Bunken I / O:

Function open and openat:

The user opens the file, the parameter is the path, and flag

The main parameters of the development of the Open flag, such as read-only, write-only, and so very, very many additional operations, specific use and can explain lookup.

Like openat to use, just openat can use relative paths to open the file, open only use absolute paths.

 

Function lseek:

Each open file has an associated file offset, he usually is a non-negative integer, to measure the number of bytes from the beginning of the file. Similarly, the parameters need to pass flag this method is invoked, setting different offsets depending on the situation.

 

Unix file system:

 

The kernel uses three data structures represent open files, their relationship determines the impact of file sharing in a process of another process that may arise

(1) Each process has a record entry in the process table, table entries contains an open file descriptors, which may be considered as a vector, a per descriptor, with each file descriptor is associated with:

  a. the file descriptor flags.

  b. Point pointer to a file entry.

(2) kernel all open files and maintain a file table, each entry contains the file:

  a. file status flags (read, write, write additions, synchronization, non-blocking, etc.)

  b. current file offset

  c. a pointer to the file entry node v

(3) each open file (the device can be considered), there is a structure node v, v node contains the file type and the file pointer to the various operations of this function for most documents, further comprising the node v i-node file (i-node index nodes). The information is read from the disk when opening files into memory, so that all relevant information files are readily available, eg, i node contains the owner of the file, the file length, the file pointing to the actual data blocks on the disk pointer or the like on the location.

Sticky bit:

  After the program was first implemented at the time of termination, if you set the sticky bit, it will save a copy in memory, the memory can be loaded faster next time execution.

Guess you like

Origin www.cnblogs.com/derek-dhw/p/11096224.html