"Understanding the Linux Kernel" study notes

Understanding the Linux Kernel reading notes

I. Introduction

The basic concept of the operating system

  • Multi-user system
    • Allows multiple users to log into the system, there is a private space between different users
  • Users and Groups
    • One for each belong to a group, permissions, rights groups and others permissions, and the owner is not the same. It corresponds to the Linux file system permissions
  • process
    • And the difference between programs. Several processes can be executed concurrently with a program, a process can perform several sequential program
    • More like a program fragment of code, the process is executing code container
    • linux is a preemptive operating system, which is a process that can take up CPU time. Non-preemptive system, if the process does not release the CPU, you can always take up
  • Core Architecture
    • Linux is a monolithic core, while providing module (Module1) Function
    • Module means: for example, a program, a reference to the system module, the system module does not have is that this process alone, when other programs need this module, the kernel will put this module is linked to other programs. This saves memory, that is, this module will only exist in a memory. A module is a set of functions, or piece of code.

File system

  • file
    • Byte information file is composed of vector sequences (Container)
    • File directory tree structure
    • Each process has a working directory, you can view the process ID command by pwdx
  • Hard links and soft connection
    • Links to similar shortcut window, and creates a file that points to another file
    • ln p1 p2 is to create a file p2, p1 points
    • Hard links can only point to a file, you can not point to a directory, as it will result in a loop point
    • Hard links can only point to a file with a file system (file system is physically divided, for example, different hard disks)
    • Soft links no hard link these limits, create method is to add the -s parameter
  • file type
    • Trivial File
    • table of Contents
    • Symbolic link
    • Device for file blocks
    • Character-oriented device file
    • Pipes and named pipes (pipe named pipe)
    • Socket (socket)
  • File descriptor and inode
    • Each file has a data structure of an index node (the inode), the content description information to storage file, and the file is divided regions.
      • inode there (see by ll command):
        • file type
        • The number of hard links
        • File length
        • File owner uid
        • id user group
        • Modification time
        • access permission
  • Access rights and file mode
    • Owner, group and others have read-write permissions to perform three kinds
  • File Operations
    • open a file
    • read
    • write
    • Move the cursor
    • shut down

Unix kernel Overview

  • Process / kernel mode
    • Process has a user mode and kernel mode
    • You can not access the kernel and user mode kernel data structures
    • Will often switch two kinds of states, for example, at time A, the process in the user mode, at time B, a process in kernel mode
    • Case of switching from user mode to kernel mode:
      • System call
      • The implementation process of the CPU sends abnormal
      • Peripheral issues an interrupt to the CPU
      • The kernel threads are executed
  • process
    • Each process has a process ID, pid
    • When the process of switching the kernel execution, saves the old process information, including:
      • The program counter and the stack pointer register
      • General-purpose registers
      • Floating-point register
      • CPU status
      • Memory management registers
  • Reentrant kernel
    • unix kernel are reentrant
    • Reentrant means, may be re-entrant, i.e. there may be multiple processes simultaneously in kernel mode
  • Process address space
    • Each process has its own private address space
  • Synchronization and critical section
    • Similar lock
    • linux is a preemptive kernel, so the need to synchronize
    • signal
      • Each resource has a semaphore, a similar type int, the initial value is 1
      • Each resource access process, down call method, a signal minus 1, minus 1 if the signal is less than 0, the process is added to the access queue. If greater than or equal to 0, the process can access resources
      • Each process complete access to resources, calling up method, semaphores plus 1, if the signal is greater than or equal to 0, the activation of the first access queue process
      • Process lock, thread-locking mechanism, should all this
      • Here we must ensure that all atomic operations up and down and can not concurrent
      • To prevent deadlocks
      • Lock region which is the critical region, i.e. between the acquire and release the code
  • And inter-process communication signals
    • Semaphores and signals are not the same
    • linux 20 different signals, for example, is a kind of signal 9 kill -9
    • After the process received signals,
      • ignore
      • Asynchronous execution of the specified program (open a new thread?), Which requires pre-defined signal processing functions.
    • After the kernel receives signals,
      • Terminate the process (eg kill - 9)
      • Ignore signals
      • Suspend the process
      • Recovery process
    • Interprocess communication (IPC)
      • signal
      • Message (msgget (), msgsnd ()) system calls, send messages and receive information between the inside of Python is to use this process Queue should be implemented
      • Shared Memory (shmget shmdt) two system calls
  • Process Management
    • fork to start a child process, generally at startup data and code duplication of the parent process, but less efficient, it will use the copy-writing, which is beginning the process of father and son shared memory, when one process needs to change when perform the copy operation
    • exec process for promoters
    • exit to end the child process
    • wait4 for the parent process to wait for the end of child process
  • Memory Management
    • Virtual memory, between physical memory (MMU) program and abstract, the equivalent access memory agent.
    • The kernel memory allocator, KMA, for memory management
    • Because cache memory is much faster than hard drives, so get from the hard disk data cached in memory, so next time you can quickly access

Guess you like

Origin www.cnblogs.com/Xjng/p/11516471.html