Basic concepts of operating system (2.1) process

Process definition, composition, organization, and characteristics

  • Definition: A process is the running process of a process entity and an independent unit for the system to allocate and schedule resources. Strictly speaking, the process and the process entity are not the same, the process is dynamic, and the process entity is static.
  • Composition: The process consists of program segments, data segments and process control block (PCB).
    • PCB: The data required by the process manager (operating system) is in the PCB
    • PCB contains: process description information, process control and management information, resource allocation list, processor related information
      • Process description information: process identifier PID, user identifier UID
      • Process control and management information: current status of the process, process priority
      • Resource allocation list: program segment pointer, data segment pointer, keyboard, mouse
      • Processor related information: various register values
  • Organization method: link method, index method
  • Features: dynamic, concurrency, independence, asynchrony, structure
    • Independence: Process is the basic unit of resource allocation and scheduling
    • Asynchrony: Asynchrony can lead to uncertainty in the execution results of concurrent programs

Process state and transition

  • The state of the process: creation state, ready state, running state, blocking state (waiting state), termination state
status CPU Other required resources
Running state
Ready state ×
Blocking state × ×

Insert picture description hereNote: The key point is the transition between running state, blocking state and ready state

Process control

  • The main function of process control is to implement effective management of all processes in the system. It has functions such as creating new processes, canceling existing processes, and realizing process state transitions.
    In short: to achieve the transition of the process state
  • Some functions of primitives (atomic, that is, uninterruptible):
    • Update the information in the PCB (modify the process status flag, save the operating environment to the PCB, restore the operating environment from the PCB)
    • Insert the PCB into the appropriate queue
    • Allocate/recycle resources
  • Related primitives of process control: process creation, process termination, process blocking, process wakeup, process switching. The blocking of the process and the wake-up of the process must occur in pairs.

Note: Atomicity is realized by on/off interrupt

Process communication

  • Shared storage: set up a shared space, and then mutually exclusive access to the shared space
    • Two ways of sharing: sharing based on data structure (low level) and sharing based on storage area (high level)
  • Pipe communication: Set up a special shared file (pipe), which is actually a buffer. Each process must have mutually exclusive access channels. One pipeline can only realize half-duplex communication, and two pipelines must be established to realize two-way communication.
    • You can't write again when it's full, and you can't read it when it's empty; you can't read if it's full, and you can't write if it's not finished.
  • Message delivery method: direct communication method (the message is sent directly to the message queue of the receiver) and indirect communication method (the message is first sent to the intermediate, that is, the mailbox).

Thread concept and multi-thread model

  • Thread: Lightweight process that can increase concurrency and reduce the overhead caused by concurrency
  • Thread attributes:
    • Thread is the unit of processor (CPU) scheduling, and process is the unit of resource allocation
    • Each thread of the same process shares resources owned by the process
    • Thread switching within the same process will not cause process switching
  • Implementation of threads: user-level threads, kernel-level threads (kernel-level threads are the unit of processor scheduling), and combination
  • Multithreaded model
    • Many-to-one model:
      Advantages: low process overhead and high efficiency.
      Disadvantages: the blocking of one thread will cause the entire process to be blocked
    • One-to-many model:
      Advantages: Each thread can be assigned to a multi-core processor for concurrent execution, with high concurrency.
      Disadvantages: process management overhead
    • Many-to-many model: combining the best of both

Guess you like

Origin blog.csdn.net/qq_45597048/article/details/112428178