Basic concepts, states and state transitions of operating system processes

Preface

This article combs the concept, state and state transition of the process.

Process definition, composition, organization and characteristics

image.png

Process definition

The three parts of program segment, data segment and PCB constitute the process entity (process image). Generally speaking, we refer to the process entity simply as the process.
The creation process is actually to create the PCB in the process entity; the
cancellation process is actually to cancel the PCB in the process entity;
PCB: process control block, used to describe various information of the process (such as the location of the program code), it is the process existence The only sign.

A process is the running process of the process entity, and an independent unit for the system to allocate resources. The thread running in the process is the basic unit of CPU scheduling.

The composition of the process

  • Program segment
    stores the program code to be executed

  • Data segment
    stores various data processed during program running, such as global variables, local variables, constants defined by macros, etc.

  • PCB (object of operating system operation process)

    • 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 ​​(when the process is switched, the current operation status of the process needs to be recorded and saved in the PCB, such as the value of the program counter (indicating which sentence of the current program is executed))

Process organization

The composition of a process refers to which parts of a
process are composed; the organization of a process refers to multiple processes, that is, the organization of multiple PCBs;

The organization of the process is divided into link mode and index mode.

  • Link method: The PCB is divided into multiple queues according to the process status, and the operating system holds pointers to each queue.
    image.png

  • Index method: According to different process states, several index tables are established, and the operating system holds pointers to each index table.
    image.png

Process characteristics

  • Dynamic: A
    process is an execution process of a program, which is dynamically produced, changed and died

  • Concurrency:
    There are multiple process entities in memory, and each process can execute concurrently

  • Independence: A
    process is a basic unit that can run independently, obtain resources independently, and establish and accept scheduling. A
    process is a basic unit for resource allocation and CPU scheduling.

  • Asynchrony:
    Each process moves forward at an independent and unpredictable speed. The operating system must provide a process synchronization mechanism to solve asynchronous problems

  • Structural:
    Each process will allocate a PCB. Structurally, the process consists of program segments, data segments, and PCB

Process state and transition

image.png

Process status

  • The New
    process in the creation state is being created, and the operating system allocates resources for the process and creates the PCB

  • The ready state Ready
    has the operating conditions, but it cannot run temporarily because it has not obtained the CPU time slice;

  • Running
    occupies the CPU and runs on the CPU; a single-core CPU has at most one process in the running state at a time, and a multi-core CPU can have multiple processes in the running state.

  • Waiting/Blocked
    is temporarily unable to run due to waiting for a certain time;

  • Terminated
    process is being cancelled from the system, the operating system will reclaim the resources owned by the process and revoke the PCB

Process state transition

image.png

How does the operating system realize the process state transition

image.png

basic concept

  • Process control is to realize the transition of process state.

  • How to realize process control, process control is realized with primitives.
    The primitive execution is atomic, and the primitive is realized by closing interrupt instructions and opening interrupt instructions.
    Primitives are implemented in the operating system kernel and run in the core state.
    image.png

  • On/off interrupt commands, they are all privileged commands
    image.png

Process control related primitives

  • Basic functions of process control primitives:
  1. Update the information in the PCB: modify the process status flag, save the operating environment to the PCB, and restore the operating environment from the PCB
  2. Insert the PCB into the appropriate queue
  3. Allocate/recycle resources
  • Creation primitive: none -> creation state -> ready state
    Conditions that cause process creation: user login, job scheduling, service provision, application request

    1. Apply for a blank PCB
    2. Allocate the required resources to the process
    3. Initialize the PCB
    4. Insert the PCB into the ready queue.
  • Cancellation primitive: ready state/blocking state/running state -> termination state -> none
    Conditions that cause the process to terminate: normal termination, abnormal termination, external intervention

    1. Find the PCB that terminated the process from the PCB collection
    2. If the process is running, immediately deprive the CPU usage rights and allocate the CPU to other processes
    3. Terminate all its child processes
    4. Return all resources owned by the process to the parent process or operating system
    5. Remove PCB
  • Blocking primitive: running state -> blocking state
    . Conditions that cause process blocking: need to wait for the system to allocate a certain resource, and need to wait for other processes that cooperate with each other to complete the work

    1. Find the PCB corresponding to the process to be blocked
    2. Protect the process running scene, set the PCB status information to the blocking state, and temporarily stop the process running
    3. Insert the PCB into the waiting queue of the corresponding event
  • Wake-up primitive: blocking state -> ready state
    The event that caused the process to wake up: the waiting event occurred

    1. Find PCB in the event waiting queue
    2. Remove the PCB from the waiting queue and set the process to the ready state
    3. Insert the PCB into the ready queue and wait to be scheduled
  • Blocking primitives and wake-up primitives must be used in pairs, the Monitor mechanism, why is it blocked, and what must be awakened

  • Switching primitives: running state -> blocking state/ready state, ready state -> running state
    Events that cause process switching: the current process time slice is reached, the process with higher priority arrives, the current process is actively blocked, and the current process is terminated

    1. Store operating environment information in PCB
    2. PCB moved to the corresponding queue
    3. Choose another process to execute and update its PCB
    4. The operating environment required to restore the new process according to the PCB

Guess you like

Origin blog.csdn.net/u014099894/article/details/112747927