[Operating system] 1. General description

What is the operating system

Operating system refers to the control and management of the hardware and software resources of the entire computer system, and the rational organization and scheduling of computer work and resource allocation to provide users and other software with a convenient interface and environment. It is the most basic computer system System software.

The function and purpose of the operating system

  1. As a systemResourcesManager of:

    • Processor management: the corresponding program is processed and CPU processed
    • Memory management: put the data related to the program into the memory
    • File management: Open the folder level by level and find the location of the QQ.exe executable file
    • Device management: assign cameras to processes
  2. AsUser and computer hardwarebetween interface:

    • Command interface : Allow users to use directly
      • Online command interface: interactive, that is, input one sentence and execute one sentence. Example: modify the system time
      • Offline command interface: batch processing, that is, input a bunch and execute a bunch. Example: *.bat file (command list)
    • Program interface: *.Dll files, users can only use indirectly through the program, composed of a set of system calls, that is, program interface = system calls
    • GUI graphical user interface
  3. As the level closest to the hardware:

    • Need to provide functions and goals: to achieve the hardware machineexpand
    • Installing the operating system on the bare metal can provide resource management functions and user-friendly service functions
    • We call the machine covered with the software an expansion machine, also known as a virtual machine

Operating system characteristics

  1. Concurrency: Two or more events occur in the same time interval,

    • At the same time macroscopically, it happens alternately at the microscopic level.
    • Confusion: Parallel-two or more events happen at the same time
  2. Sharing: Resource sharing, which means that resources in the system can be used by multiple concurrently executing processes in memory

    • Mutually exclusive sharing mode: only one process is allowed to access resources in a period of time
    • At the same time sharing: allow a period of time by multiple processes simultaneously (macro) to access them
      - the relationship between shared and concurrent: mutual presence
      to share refers to the system resources available memory in multiple concurrent processes Simultaneous use, and concurrency refers to the simultaneous existence of multiple running programs in a computer system. Therefore, if the concurrency is lost, there is only one program running in the system, and the sharing will lose its meaning. If the sharing is lost, QQ and WeChat cannot access the hard disk resources at the same time, that is, it is impossible to send files at the same time, and parallelism cannot be realized. .
  3. Virtuality: Turn a physical entity (actual existence) into several logical counterparts (perceived by the user)

    • Space division multiplexing technology: such as virtual memory technology
    • Space-time multiplexing technology: such as virtual processor
  4. Asynchrony: Refers to a multi-program environment that allows multiple programs to be executed concurrently. However, due to limited resources, the implementation of the process is not consistent to the end, but stop and go, and move forward in an unpredictable direction.

  • If concurrency is lost, there is only one program running in the system, that is, virtuality loses its meaning, and it is impossible to cause asynchrony

Operating system development stage

  1. Manual operation stage :

    • Disadvantages: The manual loading of the paper tape is slow, and the input and output speed of the paper tape is slow, and the contradiction between man and machine speed is large.
  2. Batch processing stage-single-pass batch processing system :

    • Introduce offline input and output technology (implemented by tape), and use a supervisor program (the prototype of the operating system) to control the input and output of the job.
    • Advantages: alleviate the contradiction between man and machine
    • Disadvantages: Only one program can run in the memory (serial), and the CPU has a lot of time to wait for the completion of the I/O.
  3. Batch processing stage——Multi-pass batch processing system

    • Every time you enter multiple programs into the memory, the operating system is officially born, introducing interrupt technology, and the operating system is responsible for managing the operation of these programs. Each program executes concurrently and shares computer resources.
    • advantage:Significant increase in resource utilization, CPU and other resources are in a long-term busy state.
    • Disadvantages: user response time is long, there is no human-computer interaction function, the user can only wait for the computer to complete the job after submitting the job.
    • Multi-process batch processing resource utilization efficiency is improvedthe reason: Input and output devices canparallelInstead of working serially, the device has more time to be busy.
      Insert picture description here
      Multi-pass batch processing technology
  4. Time-sharing operating system :

    • Computer withTime sliceAs a unit, serve each user/job in turn, and each user can interact with the computer through the terminal.
    • Advantages: user requests can be responded to in time,Solved the human-computer interaction problem. Allow users to use one computer at the same time.
    • Disadvantages: Some urgent tasks cannot be processed first. It is fair to all users and jobs. It serves a time slice for each user and job cyclically, without distinguishing the urgency of the task.
  5. Real-time operating system :

    • Advantages: Able to respond firstUrgent task, Some tasks do not require time slice queuing. The computer system can process in time after receiving the external signal, and the event must be processed within a strict time limit. The main features are timeliness and reliability.
    • classification:
      • Hard real-time systems: processing must be completed within an absolutely strict time limit, such as missile control systems and autopilot systems.
      • Soft real-time system: It can accept occasional violations of time regulations, such as the train ticketing system.
  6. Network operating system : to
    realize the sharing of various resources in the network and the communication between computers.

  7. Distributed operating system : The
    main feature is distribution and parallelism. Each computer in the system has the same status, and any work can be distributed on these computers, and they can complete this task in parallel and cooperatively.

  8. Personal computer operating system :
    such as windows xp, mac os, convenient for personal use.

Operating mechanism of the operating system

What are instructions?
A code in a high-level language may correspond to multiple instructions. In
simple terms, instructions are the most basic commands that the processor CPU can recognize and execute. For example, an addition instruction allows the CPU to perform an addition operation.

  1. New problem: Some instructions have very high authority, such as the memory clear instruction, if the user program can be used, it will be very dangerous, so it is dividedTwo instructions
    • Privileged instructions : such as memory clear instructions, user programs are not allowed to use
    • Non-privileged instructions : such as ordinary arithmetic instructions
  2. New question: How does the CPU judge whether it can execute privileged instructions currently?Two processor states
    • User mode (target mode) CPU can only execute non-privileged instructions at this time
    • The core state (management state) can execute privileged instructions and non-privileged instructions
    • These two states are identified by a certain flag in the program status word register (PSW).
  3. So the computer system willThere are two procedures
    • Kernel program : It is the administrator of the system. It can execute privileged instructions or non-privileged instructions and run in the core state.
    • Application Sequence: In order to ensure safe operation of the system, normal applications can execute non-privileged instructions, to run in user mode.

Operating system kernel

So which functions in the operating system should be implemented by the kernel program ?

  • The kernel is the underlying software configured on the computer, and is the most basic and core part of the operating system. (essential)
  • The programs that implement the kernel functions of the operating system are kernel programs.
  • Operating system kernel
    1. versushardwareRelatively closely related modules:
      • Clock management: realize the timing function
      • Interrupt handling: responsible for implementing the interrupt mechanism
      • Primitive:
        • Is a special program
        • At the bottom of the operating system, the part closest to the hardware
        • The operation of this kind of program is atomic-its operation is done in one go and cannot be interrupted
        • Short running time, frequent calls
    2. To the systemResourcesManagement function: (Some operating systems do not classify this part of the function as "kernel function", that is, different operating systems have different divisions of kernel functions)
      • Process management
      • Memory management
      • Equipment management

Operating system architecture

  • Generally divided into two types: large kernel structure and micro kernel structure:
  1. Large core structure
    • The main functional modules of the operating system are regarded as the system kernel, running in the core state
    • Advantages: high performance
    • Disadvantages: the kernel code is huge, the structure is chaotic, and it is difficult to maintain
  2. Microkernel structure
    • Keep only the most basic functions in the kernel
    • Advantages: less kernel functions, clear structure, easy maintenance
    • Disadvantages: Need to switch frequently between core mode and user mode, low performance

Insert picture description here

Analogy:
operating systemArchitectureversusBusiness management issuessimilar

  • The kernel is the management of the enterprise, responsible for some important tasks. Only the management can execute privileged instructions, and ordinary employees can only execute non-privileged instructions. The switch between user mode and core mode is equivalent to the handover of work between ordinary employees and management.
  1. Big core: When a company is founded, the size is small, and the management personnel will be responsible for most of the things. The advantage is that there are few people and the efficiency is high. The disadvantage is that the organization is chaotic.
  2. Microkernel: The size of the enterprise is getting bigger and bigger, and the management is only responsible for the core work. The advantage is that the organizational structure is clear and easy to maintain. The disadvantage is that the efficiency is low. When employees do some work, they have no authority and need to apply and handover continuously.

Interrupts and exceptions

  1. The birth of the interrupt mechanism :
    • Each program in the early computer could only be executed serially, and the utilization rate of system resources was low.
    • In order to solve the above problems, the operating system was invented, the interrupt mechanism was introduced, and the concurrent execution of multiple programs was realized.
    • Essence: An interruption means that the operating system needs to intervene to carry out management work
  2. The concept and function of interruption
    • whenWhen an interrupt occurs, The CPU will immediately enter the core state so that the system kernel can take over the work
    • whenAfter the interrupt, The currently running process is suspended, and the operating system kernel handles the interrupt
    • Different interrupt signals (such as: process switching, allocating I/O devices, etc.) will be processed differently
  • An interruption means that the operating system needs to intervene. Due to the operating systemManagement work requires the use of privileged instructions, So the CPU needs to enter the core state to enable the operating system to gain control of the computer. With interrupts, the concurrent execution of multiple programs can be realized .

Leftover question: How to switch between user mode and core mode?
Answer:
User mode—>Core mode: YesInterruptAchieved. andInterruption is the only way.
Core mode—>User mode: The switch is throughExecute a privileged command, Set the flag bit of the program status word (PSW) to "user mode"

  1. Classification of interrupts

    • Internal interruptabnormal, Exception caught) Signal Source: Internal the CPU , and the currently executing instruction related .
      • Voluntary interruption-instruction interruption: For example, the access control instruction (also called trap instruction) used in system calls is an intentional exception.
      • Forced interruption
        • Hardware failure: such as missing pages
        • Software interrupt: such as dividing an integer by 0
    • External interruptInterrupt) Signal source: outside the CPU , has nothing to do with the currently executed instruction
      • Peripheral request: such as the interrupt signal issued after the completion of the I/O operation
      • Manual intervention: If the user forcibly terminates a program
  2. External interrupt processing

    1. After executing each instruction, the CPU must check whether it is currently interrupted by an external signal
    2. If an external interrupt signal is detected, you needprotectionOf the interrupted processCPU environment(Archive) (such as program status word, program counter PC, various general registers)
    3. according toType of interrupt signalTransfer to the corresponding interrupt handler
    4. Restore the CPU environment of the original process and exit the interrupt, return to the original process to continue execution
      Insert picture description here

System call

  • System call-is provided by the operating system toapplicationThe interface used by (programmer/programmer) can be understood as a special function that can be called by the application program. The application program can issue a system call request to obtain the service of the operating system .The system call will cause the processor CPU to enter the core state from the user mode
    Insert picture description here

Why does the operating system provide system call functions?
Life scenario:
In the print shop, when your document is halfway through, another person also prints his document on the computer and clicks to print, but the second half of your document is not mixed with his document. This is Because the system provides a system call function.
If a user process wants to use a shared resource such as a printer, it can only send a request to the operating system through a system call, and the operating system will coordinate and manage each request.

  • Each in the systemShare resourceAll operating systems are under unified control, so in the user program,All operations related to resources(Such as storage allocation, I/O operation, file management),Must be called by the systemRequest services to the operating system, and the operating system will complete it on its behalf . This can ensure the stability and security of the system and prevent users from performing illegal operations.

  • System call related processing involves the management of system resources and the control of processes . These functionsNeed to execute some privileged instructionsCan be completed, so the related processing of the system call needs to beCore stateTo complete.

  • The truth behind the system call :
    Insert picture description here

Insert picture description here

  • process:
    1. Pass system call parameters movl instruction
    2. Execute the trapped instruction (run in user mode), enter the core mode immediately after running
    3. Execute system call related application service program (running in core state)
    4. Return to user program
  • note:
    1. The trap instruction isExecute in user mode, Immediately after the execution is completed, aInternal interrupt, So that the CPU entersCore state
    2. issue(Occurs) The system call request is inUser mode, And the call to the systemDeal withIs inCore stateUnderway
    3. Stuck in orderIs the only oneCan only be executed in user mode,andCannot be executed in core modeInstruction

The difference between system calls and library functions :
Insert picture description here
Insert picture description here

  • Library functions that do not involve system calls: such as functions that take absolute values
  • Library functions involving system calls: such as a function to create a file

Guess you like

Origin blog.csdn.net/Qmilumilu/article/details/112426228