Linux network programming reading note notes are streamlined by the content of the book, plus my personal point of view. Note: Zhangyv Date:
2005-1-15
Title: Linux Network Programming Author: Lin Yu Guo Lingyun Press: People's Posts and Telecommunications Difficulty: Beginner to advanced systems and processes first chapter of the document system
1.1 Overall structure of the file system
From the perspective of the file system, it can be divided into applications, system calls, subsystems, high-speed buffer, device drivers, and specific storage devices, as shown below:
In the UNIX system, the program is organized by the core, just treat the file as an unformatted byte stream. The access syntax for the file is defined by the system, the semantics of the data are made by the program.
The application process passes the system call to access the file system, assigned to a standard general interface to the application to facilitate the difference in different file systems. The file system cannot access the hardware device directly, and the specific device is operated by calling the device driver process. Access to high-speed equipment, usually improves equipment and memory data exchange through a high speed buffer mechanism. The device driver process is used to block the difference in operation of different physical devices.
The overall structure of the file system is: boot block, super block, index node table, data area.
· Guide blocks in the forefront of the file system, it is related to the operating system boot. There is only one guiding block to be valid.
· Super block is also called managing blocks, stores management information of file systems, such as file system size, idle block size, idle block, and other information.
· Index node table, each file corresponds to an index node, and inside the user's access rights, information, etc. By path access file, the kernel maps the file path to the corresponding node in the index node table.
· Data area. The file system actually stores the disk space of the data.
· Idle data block table. The space in the hyper block is small, so writes the information of the idle data block in the data area.
VFS (Virtual FileSystem Switch)
Linux implements multi-file system support through virtual file system conversion. Linux converts system calls to file operations to subroutine calls that do not operate through file system, which are written for specific file systems. The virtual file system is not a real file system, but a mapping mechanism to shield the difference in the lower layer to facilitate the upper layer.
1.2 file structure and directory structure
Each file in Linux corresponds to an index node of the virtual file system, which is stored in a direct or multi-level pointer to record the files, so that the design is to access a large file.
The directory can also be abstracted into documents, and also describe the index node table and store the directory item in the directory table in the data area. The basic component of the catalog table is a directory entry, with the "file name - index node". The file node index table does not include the file name, and the file name is filled in in the directory file.
· Differences for hard connection and symbol (soft) connection:
The function symbolic connection that the hard connection can be implemented can be implemented. Hard connections can only be used in file (non-directory) and the same file system, but the symbol connection applies to the directory and also applies to different file systems. However, the symbol connection consumes kernel resources than hard connectivity, as the conversion rule of the symbol connection is implemented in the kernel, and hard connection directly points to the index node.
Hard connection is the correspondence between the file name and the index node; the symbol connection is the path to the file.
· File system related programming:
From the perspective of the system's implementation point, the file in the file is indicated by the uniquely determined index node. If a programming perspective, the file can be represented by a file descriptor and a file pointer. There are Open, Write, Read, Close, IOCTL, including Open, Write, Read, Close, IOCTL, etc. in the UNIX I / O library to operate file descriptors.
In the C library function, Fopen, FPRINTF, FREAD, FWRITE, FCLOSE and other file operation functions are processed on the file pointer, which is a reassembly of the system call.
From the system perspective: The file handle is a flag of the file, which is the index number in the file descriptor table. The file descriptors of the process of the process, output, and error output are 0, 1, 2 in Unistd.h, which are defined as stdin_fileno, stdout_fileno, and stderr_fileno. From the C function library perspective: The file handle is a pointer to the file structure. . The logo input, output, and error output are defined in stdio.H as stdin, stdout, stderr. You can use the system call fileno () to turn a file pointer to a file descriptor.
1.3 process system
· Problem in parallel execution:
The concept of static programs cannot be well described in parallel environments, so the concept of the introduced process. In a single-way programming, the environment is closed, and the resources are always exclusive; in parallel environments, due to the exclusive sexuality of closure and resources, this will result in many problems.
· The difference between processes and procedures:
The program is a collection of instructions and data. It is a static text that is stored in a normal file, which is "executable" in the index node table.
The process is the process of running once in an environment including instruction segments, systems, and user data, to complete the predetermined task. After the process is revoked, no longer exists, and the text of the program remains in the system.
· The physical representation of the process:
To describe the process of dynamic changes, we divide the process into 3 parts: the program part, the data section, and the process control block - unified called a process image.
The program part of the process can be shared by multiple programs, the shared code segment should be written into a pure code PUER Code, that is, the functionality of the block does not differ with the procedure called the program.
The data area and work unit executed by the program section. When the execution is not a shared code segment, part of the data is placed in the data space.
Each process has a process control block PCB that tracks and records the data structure of the dynamic changes, and the data structure of the information, which reflects the characteristics of the process, the status, and other processes.
· The virtual space of the process:
The void space of the operating system can be divided into "process via" and "system virtual space".
The executable program is executed, and the data corresponds to the address of the process virtual space, and the process virtual space address is mapped to physical memory by the operating system. This mapping is achieved by hardware registers and system pages.
· User-state and core state:
User-state and core states are actually two different modes of CPU work. All kernels provided are in the form of system calls. The process is once systematically calling, the CPU will switch between the user state and the core state, and the system calls work at the core stack, and the normal user call will use the user stack.
· Process context:
The process can be described in all states in the lifetime. Typically, three contents:
1 User-level context: including code segments, data segments, user segments, and shared memory segments.
2 Register Context: The contents of each register when the process is running
3 System Level Context: Process Control Block, Page Table and Core Stack Used by Process
· Process conversion
· Process schedule:
The core will call the schedule manager in several cases: When the current process is placed in a waiting queue or when the system call is ended, and when the core state is returned to the client.
(1) Linux supports two types of different processes: ordinary and real-time processes, which are reflected in priority and scheduling strategies.
(2) If a real-time process is in executable, it is always performed before any normal process.
(3) The real-time process uses two call strategies: the time slice rotation and advanced first.
(4) The normal process uses the Round Robin Strategy.
(5) Priority process priority, RT_PRIORITY real-time process priority, Counter process running time
· Understanding for Fork:
The Tast_Struc of the father and son process after Fork In addition to the process number, the other data is the same. Use the void technology, share code segment (reference count plus 1), copy data segments. Forck Fak Fixed Sub-process is established and saves the context to enter the ready queue waiting schedule. After the FORK is completed, the parent process context is saved, the process identifier of the sub-process is saved. Note: The Fork call of the child process returns 0, the parent process fork call returns the process number of the child process. The parent child process will continue to run from the call point of Fork. Before the parent process exits, you need to use Wait () or WAIPID () waiting to perform the subscription and clear the zombie process to release resources.
Chapter 1 File System and Process System
1.1 Overall structure of the file system
From the perspective of the file system, it can be divided into applications, system calls, subsystems, high-speed buffer, device drivers, and specific storage devices, as shown below:
In the UNIX system, the program is organized by the core, just treat the file as an unformatted byte stream. The access syntax for the file is defined by the system, the semantics of the data are made by the program.
The application process passes the system call to access the file system, assigned to a standard general interface to the application to facilitate the difference in different file systems. The file system cannot access the hardware device directly, and the specific device is operated by calling the device driver process. Access to high-speed equipment, usually improves equipment and memory data exchange through a high speed buffer mechanism. The device driver process is used to block the difference in operation of different physical devices.
The overall structure of the file system is: boot block, super block, index node table, data area.
· Guide blocks in the forefront of the file system, it is related to the operating system boot. There is only one guiding block to be valid.
· Super block is also called managing blocks, stores management information of file systems, such as file system size, idle block size, idle block, and other information.
· Index node table, each file corresponds to an index node, and inside the user's access rights, information, etc. By path access file, the kernel maps the file path to the corresponding node in the index node table.
· Data area. The file system actually stores the disk space of the data.
· Idle data block table. The space in the hyper block is small, so writes the information of the idle data block in the data area.
VFS (Virtual FileSystem Switch)
Linux implements multi-file system support through virtual file system conversion. Linux converts system calls to file operations to subroutine calls that do not operate through file system, which are written for specific file systems. The virtual file system is not a real file system, but a mapping mechanism to shield the difference in the lower layer to facilitate the upper layer.
1.2 file structure and directory structure
Each file in Linux corresponds to an index node of the virtual file system, which is stored in a direct or multi-level pointer to record the files, so that the design is to access a large file.
The directory can also be abstracted into documents, and also describe the index node table and store the directory item in the directory table in the data area. The basic component of the catalog table is a directory entry, with the "file name - index node". The file node index table does not include the file name, and the file name is filled in in the directory file.
· Differences for hard connection and symbol (soft) connection:
The function symbolic connection that the hard connection can be implemented can be implemented. Hard connections can only be used in file (non-directory) and the same file system, but the symbol connection applies to the directory and also applies to different file systems. However, the symbol connection consumes kernel resources than hard connectivity, as the conversion rule of the symbol connection is implemented in the kernel, and hard connection directly points to the index node.
Hard connection is the correspondence between the file name and the index node; the symbol connection is the path to the file.
· File system related programming:
From the perspective of the system's implementation point, the file in the file is indicated by the uniquely determined index node. If a programming perspective, the file can be represented by a file descriptor and a file pointer. There are Open, Write, Read, Close, IOCTL, including Open, Write, Read, Close, IOCTL, etc. in the UNIX I / O library to operate file descriptors. In the C library function, Fopen, FPRINTF, FREAD, FWRITE, FCLOSE and other file operation functions are processed on the file pointer, which is a reassembly of the system call.
From the system perspective: The file handle is a flag of the file, which is the index number in the file descriptor table. The file descriptors of the process of the process, output, and error output are 0, 1, 2 in Unistd.h, which are defined as stdin_fileno, stdout_fileno, and stderr_fileno.
From the C function library perspective: The file handle is a pointer to the file structure. . The logo input, output, and error output are defined in stdio.H as stdin, stdout, stderr. You can use the system call fileno () to turn a file pointer to a file descriptor.
1.3 process system
· Problem in parallel execution:
The concept of static programs cannot be well described in parallel environments, so the concept of the introduced process. In a single-way programming, the environment is closed, and the resources are always exclusive; in parallel environments, due to the exclusive sexuality of closure and resources, this will result in many problems.
· The difference between processes and procedures:
The program is a collection of instructions and data. It is a static text that is stored in a normal file, which is "executable" in the index node table.
The process is the process of running once in an environment including instruction segments, systems, and user data, to complete the predetermined task. After the process is revoked, no longer exists, and the text of the program remains in the system.
· The physical representation of the process:
To describe the process of dynamic changes, we divide the process into 3 parts: the program part, the data section, and the process control block - unified called a process image.
The program part of the process can be shared by multiple programs, the shared code segment should be written into a pure code PUER Code, that is, the functionality of the block does not differ with the procedure called the program.
The data area and work unit executed by the program section. When the execution is not a shared code segment, part of the data is placed in the data space.
Each process has a process control block PCB that tracks and records the data structure of the dynamic changes, and the data structure of the information, which reflects the characteristics of the process, the status, and other processes.
· The virtual space of the process:
The void space of the operating system can be divided into "process via" and "system virtual space".
The executable program is executed, and the data corresponds to the address of the process virtual space, and the process virtual space address is mapped to physical memory by the operating system. This mapping is achieved by hardware registers and system pages.
· User-state and core state:
User-state and core states are actually two different modes of CPU work. All kernels provided are in the form of system calls. The process is once systematically calling, the CPU will switch between the user state and the core state, and the system calls work at the core stack, and the normal user call will use the user stack.
· Process context:
The process can be described in all states in the lifetime. Typically, three contents:
1 User-level context: including code segments, data segments, user segments, and shared memory segments.
2 Register Context: The contents of each register when the process is running
3 System Level Context: Process Control Block, Page Table and Core Stack Used by Process
· Process conversion
· Process schedule:
The core will call the schedule manager in several cases: When the current process is placed in a waiting queue or when the system call is ended, and when the core state is returned to the client.
(1) Linux supports two types of different processes: ordinary and real-time processes, which are reflected in priority and scheduling strategies.
(2) If a real-time process is in executable, it is always performed before any normal process. (3) The real-time process uses two call strategies: the time slice rotation and advanced first.
(4) The normal process uses the Round Robin Strategy.
(5) Priority process priority, RT_PRIORITY real-time process priority, Counter process running time
· Understanding for Fork:
The Tast_Struc of the father and son process after Fork In addition to the process number, the other data is the same. Use the void technology, share code segment (reference count plus 1), copy data segments. Forck Fak Fixed Sub-process is established and saves the context to enter the ready queue waiting schedule. After the FORK is completed, the parent process context is saved, the process identifier of the sub-process is saved. Note: The Fork call of the child process returns 0, the parent process fork call returns the process number of the child process. The parent child process will continue to run from the call point of Fork.
Before the parent process exits, you need to use Wait () or WAIPID () waiting to perform the subscription and clear the zombie process to release resources.