OS learning notes-3: process


OS learning notes-3: process

1. About the process

1.1 process:

In order to facilitate the management of the operating system, the concept of process is introduced to control and describe the concurrent execution of each program.

1.2 PCB:


In the previous single channel batch processing system, the program was executed serially, and only the degree segment and data segment of a single program may be recorded in memory; but now the multi-channel batch processing system is used, and multiple programs are executed concurrently, and there may be multiple program segments and data segments of their own in memory, so a management unit is needed to distinguish these things , description and management, so there’s one moreProcess control block, that is, PCB.

The system will assign a PCB data structure to each running program to describe various information of the process. PCB is the only sign of the existence of the process, and the process and PCB are one-to-one corresponding.

The PCB records information about the process, including:

  • Process status: process identifier, current status of the process
  • Program counter: the address of the next instruction to execute the program
  • CPU register: provide on-site protection, record various status information of CPU, facilitate future recovery
  • CPU scheduling information: including CPU priority, scheduling queue pointer, etc
  • Memory management information: base register, limit register, etc
  • Accounting information: CPU time, usage time, number of processes, etc
  • I / O status information: list of I / O devices assigned to the process, open file list, etc
  • Communication information: recording communication between processes

1.3 process entity:

Program segment(program code)Data segment(variables, constants, etc.),PCB(related management information) together constitutes the process entity (process image). Generally, the process entity = = = process = = = PCB

PS: the organization mode of multiple processes mentioned below, that is to say, the organization mode of multiple PCBs

1.4 comparison of process and procedure:

  • The process isDynamicA program is static (a collection of ordered code)
  • The process is temporary, the program is permanent
  • The composition of processes and procedures is different
  • Through multiple execution, a program can correspond to multiple processes; through call relationship, a process can include multiple programs

2. Composition and organization of the process

2.1 composition of single process

  • Process description information: process identifier PID (distinguish different processes) user identifier uid (distinguish different users)
  • Process control and management information: current status and priority of the process
  • Resource allocation list: program segment pointer, data segment pointer, key mouse
  • Processor related information: values of various registers

2.2 organization of multiple processes

  • Link mode:

    The PCB is divided into multiple queues according to the process status, and the OS holds pointers to each queue (execution pointer, ready queue pointer, blocking queue pointer)

  • Index method: create several index tables according to the process status, and the OS holds the pointers to each index table (execution pointer, ready table pointer, blocking table pointer)

3. Characteristics of the process

  • Dynamism: a process is an execution of a program. It isDynamicallyArising, changing and dying
  • Concurrency: there are multiple process entities in memory, and each process can execute concurrently
  • Independence: a process is one of the resources allocated and scheduled by the systemIndependent unit
  • Asynchrony: each process advances at an independent and unpredictable speed
  • Structure: each process has its own PCB, which is composed of degree segment, data segment and PCB

4. State / life cycle of process

4.1 five basic states:

Create state: allocate resources for the process and initialize PCB

Running state: occupy the CPU usage right and run on the CPU (for a single core processor, there will only be one process at a time)

Ready state: everything is ready (all the conditions needed for operation are available), only Dongfeng (only waiting for the CPU to be idle so that it can run on it)

Blocking state (waiting state): when a process makes a system call or waits for an event to occur, it enters blocking state

End state (end state): reclaim the resources allocated for the process, and cancel the PCB

4.2 process state transition:

OS learning notes-3: process

4.3 after importing pending operation

(1) Pending:

The state transition mentioned above is based on the condition that the memory resources are sufficient — when the system resources, especially the memory resources are insufficient, some processes need to be changedHang up(suspend), swap to external storage.

(2) Reason:

There are various reasons for process suspension, including:

  • The processes in the system are in blocking state, and the processor is idle. At this time, some blocking processes need to be swapped outFree up enough memoryThe mount ready process runs.
  • Processes compete for resources, resulting in systemsInsufficient resources, the load is too heavy. At this time, some processes need to be suspended to adjust the system load to ensure the real-time performance or normal operation of the system.
  • Exchange some regularly executed processes (such as audit procedures, monitoring procedures, accounting procedures) toReduce system load
  • User requirementsSuspend your own process for some debugging, checking, and correction based on intermediate execution and intermediate results.
  • Parent processRequires that you suspend your descendant processes for some checks and corrections.
  • operating systemSome processes need to be suspended to check the use of running resources to improve system performance; or some processes need to be suspended to troubleshoot when the system fails or some functions are damaged.

(3) State transition

After the introduction of suspend operation, there are two more states based on the original five states: ready state becomes active ready state, and there is one more “static ready state / suspended ready state”; the original blocking state becomes active blocking state, and there is one more “static blocking state / suspended blocking state”.

OS learning notes-3: process

state explain
Active ready state → static ready state According to the current resource status and performance requirements, the operating system may swap out the active ready state to the static ready state.Processes in static ready state are no longer scheduled for execution
Static ready → active ready No process in memory is in the active ready state, or the process in the static ready state has a higher priority, then the static ready state will be swapped back, and then it can be scheduled for execution
Active blocking state → static blocking state According to the current resource status and performance requirements, the operating system may swap out the active blocking state to static blocking state.
Static blocking state → static ready state A common situation is that after the event that causes the process to wait, the corresponding static blocking process will be converted to the static ready state
Static blocking state → active blocking state But sometimes, ifStatic blocking processPriority is higher thanAny process in the quiesce ready queue, and the system is sure that the event it is waiting for is about to be completed, then it will be activated as an active blocking state
Running state → static ready state The higher priority static blocking state may seize the CPU after the waiting event is completed. If the resource is not enough at this time, the running process may be suspended as static ready state
Create state → static ready state According to the current resource status and performance requirements, the operating system may swap it to external storage after the process is created

PS:Once a process is suspended, it means that it is swapped to external memory. At this time, the process can no longer be directly scheduled by the CPU unless it is swapped back to memory and back to the active ready state. For example, static ready state, static blocking state, and finally CPU scheduling must go throughReturn to activity readyThe process.

Reference resources:

State transition of process