Operating Systems: Process Management and Scheduling | 操作系统:进程管理与调度

📚 Operating Systems: Process Management and Scheduling | 操作系统:进程管理与调度

An operating system (OS) is the fundamental software that manages computer hardware and provides services for application programs. In A‑Level Computer Science, understanding how the OS handles processes and schedules CPU time is critical. This article explores the key concepts of process management and scheduling algorithms, essential for Edexcel exam success.

操作系统是管理计算机硬件并为应用程序提供服务的底层软件。在A‑Level计算机科学中,理解操作系统如何处理进程以及调度CPU时间是至关重要的。本文探讨进程管理和调度算法的核心概念,这对Edexcel考试成功至关重要。

1. What is an Operating System? | 什么是操作系统?

An operating system acts as an intermediary between the user and the computer hardware. Its main roles include resource management (CPU, memory, I/O devices), process management, file system management, and providing a user interface. Without an OS, applications would need to directly control hardware, making software development extremely complex.

操作系统充当用户与计算机硬件之间的中介。它的主要职责包括资源管理(CPU、内存、I/O设备)、进程管理、文件系统管理以及提供用户界面。如果没有操作系统,应用程序将需要直接控制硬件,使得软件开发极其复杂。


2. The Concept of a Process | 进程的概念

A process is a program in execution. It is more than just the program code; it includes the current activity, as represented by the program counter, processor registers, and memory addresses. A process can be in one of several states as it runs and waits for events.

进程是正在执行的程序。它不仅仅是程序代码,还包括当前活动,由程序计数器、处理器寄存器和内存地址表示。进程在运行和等待事件时可能处于多种状态之一。


3. Process States and Transitions | 进程状态及其转换

The typical process states are: New (being created), Ready (waiting to be assigned to a processor), Running (instructions are being executed), Waiting/Blocked (waiting for some event, such as I/O completion), and Terminated (finished execution). Transitions occur when a process is scheduled, issues an I/O request, or is interrupted.

典型的进程状态有:新建(正在创建)、就绪(等待分配处理器)、运行(正在执行指令)、等待/阻塞(等待某事件,如I/O完成)和终止(执行完毕)。状态转换发生在进程被调度、发出I/O请求或被中断时。


4. Process Control Block (PCB) | 进程控制块

Each process is represented in the OS by a Process Control Block (PCB). It contains process ID, program counter, CPU registers, memory management information, scheduling information (priority, pointer to queue), and I/O status. The PCB is saved and restored during context switches.

每个进程在操作系统中由一个进程控制块(PCB)表示。它包含进程ID、程序计数器、CPU寄存器、内存管理信息、调度信息(优先级、队列指针)以及I/O状态。在进行上下文切换时,PCB被保存和恢复。


5. Scheduling Queues | 调度队列

The OS maintains various queues for process scheduling: the job queue holds all processes in the system; the ready queue contains processes residing in main memory, ready to run; and device queues hold processes waiting for an I/O device. These queues are typically linked lists.

操作系统维护各种用于进程调度的队列:作业队列包含系统中的所有进程;就绪队列包含驻留在主存中、准备运行的进程;设备队列包含等待I/O设备的进程。这些队列通常是链表。


6. CPU Scheduling Criteria | CPU调度标准

Scheduling algorithms are evaluated using criteria such as CPU utilisation (keep CPU busy), throughput (number of processes completed per unit time), turnaround time (time from submission to completion), waiting time (time spent in ready queue), and response time (time from submission to first response).

调度算法的评估标准包括CPU利用率(保持CPU忙碌)、吞吐量(单位时间完成的进程数)、周转时间(从提交到完成的时间)、等待时间(在就绪队列中花费的时间)以及响应时间(从提交到首次响应的时间)。


7. First-Come, First-Served (FCFS) | 先来先服务调度

FCFS is the simplest scheduling algorithm. The process that requests the CPU first is allocated the CPU first. It is implemented using a FIFO queue. However, it can lead to the convoy effect, where short processes wait behind long processes, increasing average waiting time.

FCFS是最简单的调度算法。最先请求CPU的进程最先获得CPU。它使用FIFO队列实现。然而,它可能导致护航效应,即短进程等待在长进程后面,增加平均等待时间。

Example: P1 burst=24, P2 burst=3, P3 burst=3. If order is P1, P2, P3, waiting times: P1=0, P2=24, P3=27; average = 17. If order P2, P3, P1, average = 3. This shows how FCFS is sensitive to arrival order.

例如:P1爆发时间=24,P2=3,P3=3。如果顺序是P1、P2、P3,等待时间:P1=0,P2=24,P3=27;平均=17。如果顺序P2、P3、P1,平均=3。表明FCFS对到达顺序敏感。


8. Shortest Job First (SJF) | 最短作业优先调度

SJF selects the process with the smallest next CPU burst. It is optimal in minimising average waiting time. SJF can be preemptive or non‑preemptive. Preemptive SJF (Shortest Remaining Time First) preempts if a new process arrives with a shorter burst than the remaining time of the current process.

SJF选择下一次CPU爆发时间最短的进程。它在最小化平均等待时间方面是最优的。SJF可以是抢占式或非抢占式。抢占式SJF(最短剩余时间优先)如果新到达进程的爆发时间比当前进程剩余时间更短,则抢占。

SJF requires knowledge of future burst lengths. Usually, predicted using exponential averaging. The prediction formula is:

τₙ₊₁ = α tₙ + (1 − α) τₙ

where tₙ is the actual CPU burst, τₙ is the predicted burst, and α is a weight factor (0 ≤ α ≤ 1). This prediction enables the scheduler to approximate SJF.

SJF需要知道未来的爆发长度,通常使用指数平均进行预测。预测公式为:

τₙ₊₁ = α tₙ + (1 − α) τₙ

其中tₙ是实际CPU爆发时间,τₙ是预测值,α是权重因子(0 ≤ α ≤ 1)。此预测使调度器能够近似实现SJF。


9. Priority Scheduling | 优先级调度

A priority is associated with each process, and the CPU is allocated to the process with the highest priority. Priorities can be static or dynamic. Priority scheduling can be preemptive or non‑preemptive. A major problem is starvation, where low‑priority processes may never execute.

每个进程关联一个优先级,CPU分配给最高优先级的进程。优先级可以是静态或动态的。优先级调度可以是抢占式或非抢占式。一个主要问题是饥饿,即低优先级进程可能永远无法执行。

Solution: aging – gradually increase the priority of waiting processes over time. Eventually, even a low‑priority process will attain high priority and be executed.

解决方案:老化——随时间逐渐增加等待进程的优先级。最终,即使低优先级进程也会获得高优先级并执行。


10. Round Robin Scheduling | 轮转调度

Round Robin (RR) is designed for time‑sharing systems. Each process gets a small unit of CPU time called a time quantum (typically 10‑100 ms). After a quantum, if the process is still running, it is preempted and added to the tail of the ready queue. RR provides good response time and fairness.

轮转调度(RR)专为分时系统设计。每个进程获得一小段CPU时间,称为时间片(通常10‑100毫秒)。一个时间片后,如果进程仍在运行,它被抢占并添加到就绪队列尾部。RR提供了良好的响应时间和公平性。

Performance depends on quantum size: small quantum leads to many context switches, increasing overhead; large quantum degrades to FCFS. A rule of thumb: 80% of CPU bursts should be shorter than the quantum.

性能取决于时间片大小:小时间片导致许多上下文切换,增加开销;大时间片退化为FCFS。经验法则:80%的CPU爆发应短于时间片。


11. Multilevel Queue Scheduling | 多级队列调度

Processes are partitioned into groups (e.g., interactive, batch) with different response‑time requirements. Each group has its own queue and its own scheduling algorithm. For example, foreground queue uses RR, background queue uses FCFS. Scheduling among queues can be fixed‑priority preemptive or time‑sliced.

进程被划分为具有不同响应时间要求的组(例如交互式、批处理)。每个组有自己的队列和自己的调度算法。例如,前台队列使用RR,后台队列使用FCFS。队列之间的调度可以是固定优先级抢占式或时间片划分。


12. Context Switching | 上下文切换

Switching the CPU from one process to another requires saving the state (PCB) of the old process and loading the saved state of the new process. This is called a context switch. It is pure overhead, as the system does no useful work while switching. The time depends on hardware support (e.g., multiple register sets).

将CPU从一个进程切换到另一个进程需要保存旧进程的状态(PCB)并加载新进程的已保存状态。这称为上下文切换。它是纯粹的开销,因为系统在切换时不执行任何有用工作。时间取决于硬件支持(例如多组寄存器)。

Frequent

Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version