Process Scheduling in Operating Systems | 操作系统中的进程调度

📚 Process Scheduling in Operating Systems | 操作系统中的进程调度

Process scheduling is a fundamental function of an operating system that decides which process runs at a given time on the CPU. It lies at the heart of multitasking and ensures efficient, fair, and responsive use of processor resources. Understanding scheduling algorithms is essential for A-Level Computer Science, as it links directly to system performance analysis and concurrent programming concepts.

进程调度是操作系统的一项基本功能,它决定在给定时刻哪个进程在 CPU 上运行。它是多任务处理的核心,确保处理器资源得到高效、公平且及时的利用。理解调度算法对 A-Level 计算机科学至关重要,因为它直接关联到系统性能分析和并发编程概念。


1. What is a Process? | 什么是进程?

A process is a program in execution. It consists of the program code (text section), program counter, CPU registers, stack, data section, and heap. While a program is a passive entity stored on disk, a process is an active entity with its own state and resources allocated by the operating system.

进程是一个正在执行的程序。它由程序代码(文本段)、程序计数器、CPU 寄存器、栈、数据段和堆组成。程序是存储在磁盘上的被动实体,而进程是一个主动实体,拥有自己的状态和操作系统分配的资源。


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

Each process is represented in the OS by a Process Control Block (PCB). The PCB contains vital information: process ID, program counter, CPU registers, memory limits, list of open files, and scheduling information like priority and process state. When the CPU switches from one process to another, it saves the current PCB and loads the next process’s PCB — this is a context switch.

每个进程在操作系统中都由一个进程控制块(PCB)表示。PCB 包含重要信息:进程 ID、程序计数器、CPU 寄存器、内存界限、打开文件列表以及调度信息(如优先级和进程状态)。当 CPU 从一个进程切换到另一个进程时,它会保存当前 PCB 并加载下一个进程的 PCB——这就是上下文切换。


3. Process States | 进程状态

A process transitions through several states during its lifetime: New, Ready, Running, Waiting, and Terminated. In the Ready state, it waits for CPU allocation. In the Running state, instructions execute. If the process must wait for an I/O event, it moves to the Waiting state until that event completes.

进程在其生命周期中会经历多个状态:新建、就绪、运行、等待和终止。在就绪状态下,它等待 CPU 分配。在运行状态下,指令得以执行。如果进程必须等待 I/O 事件,它会转移到等待状态,直到该事件完成。


4. Scheduling Queues | 调度队列

Operating systems maintain three main queues: the job queue (all processes entering the system), the ready queue (processes residing in main memory, ready to run), and device queues (processes waiting for particular I/O devices). A process migrates among these queues based on its state and scheduling decisions.

操作系统维护三种主要队列:作业队列(所有进入系统的进程)、就绪队列(驻留在主存中、准备运行的进程)以及设备队列(等待特定 I/O 设备的进程)。进程根据其状态和调度决策在这些队列之间迁移。


5. Types of Schedulers | 调度程序类型

Long-term schedulers (job schedulers) admit processes from disk to the ready queue, controlling the degree of multiprogramming. Short-term schedulers (CPU schedulers) select the next process from the ready queue to execute. Medium-term schedulers swap processes out of memory temporarily to reduce multiprogramming load and improve responsiveness.

长期调度程序(作业调度程序)将进程从磁盘送入就绪队列,控制多道程序的度。短期调度程序(CPU 调度程序)从就绪队列中选择下一个进程执行。中期调度程序暂时将进程换出内存,以降低多道程序负载并改善响应速度。


6. CPU Scheduling Criteria | CPU 调度标准

When evaluating scheduling algorithms, several criteria are used: CPU utilisation (keep the CPU busy), throughput (number of processes completed per time unit), turnaround time (time from submission to completion), waiting time (time spent in the ready queue), and response time (time from submission until the first response).

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


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

FCFS allocates CPU to processes in the order they arrive. It is simple to implement with a FIFO queue. However, it suffers from the convoy effect: a long CPU-bound process can hold up many short I/O-bound processes, leading to high average waiting time. It is non-preemptive.

FCFS 按照进程到达的顺序分配 CPU。它使用先进先出队列实现简单。但它存在护航效应:一个长 CPU 密集型进程可能阻塞许多短 I/O 密集型进程,导致平均等待时间很高。它是非抢占式的。

  • Convince effect example: P1 (burst time 20), P2 (burst 5), P3 (burst 2). Average waiting time = (0 + 20 + 25) / 3 = 15 units.
  • 护航效应举例:P1(执行时间 20)、P2(5)、P3(2)。平均等待时间 = (0 + 20 + 25)/3 = 15 单位。

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

SJF assigns CPU to the process with the smallest next CPU burst time. It minimises average waiting time for a given set of processes. It can be preemptive (Shortest Remaining Time First) or non-preemptive. Its main drawback is the difficulty of predicting burst lengths; it may also cause starvation for longer processes.

SJF 将 CPU 分配给下一次 CPU 执行时间最短的进程。它能使给定进程集合的平均等待时间最小。它可以是抢占式(最短剩余时间优先)或非抢占式。主要缺点是难以预测执行时长;还可能导致长进程饥饿。


9. Priority Scheduling | 优先级调度

Each process is assigned a priority, and the CPU is given to the highest-priority ready process. Priorities can be static or dynamic (ageing to prevent starvation). A major problem is indefinite blocking of low-priority processes. In a preemptive system, a higher-priority arriving process can preempt a currently running lower-priority process.

每个进程被分配一个优先级,CPU 分配给就绪队列中优先级最高的进程。优先级可以是静态的或动态的(老化技术防止饥饿)。主要问题是低优先级进程可能无限期阻塞。在抢占式系统中,到达的高优先级进程可以抢占当前正在运行的低优先级进程。


10. Round Robin (RR) Scheduling | 轮转调度

RR allocates each process a fixed time quantum (typically 10–100 ms). The ready queue is circular; if a process exceeds its quantum, it is preempted and placed at the back. This ensures fair CPU distribution and excellent response time for interactive systems. Performance depends heavily on the quantum size — too short increases context switches, too long degrades to FCFS.

RR 给每个进程分配一个固定的时间片(通常 10–100 毫秒)。就绪队列是环形的;如果进程超出其时间片,它会被抢占并放回队尾。这确保了公平的 CPU 分配和交互系统出色的响应时间。性能很大程度上取决于时间片大小——太短会增加上下文切换开销,太长则退化为 FCFS。


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

The ready queue is partitioned into separate queues, such as foreground (interactive) and background (batch) queues, each with its own scheduling algorithm. Fixed-priority preemptive scheduling between queues is common. Some systems allow processes to move between queues based on their behaviour (multilevel feedback queue).

就绪队列被划分成几个独立队列,例如前台(交互式)队列和后台(批处理)队列,每个队列有自己的调度算法。队列之间通常采用固定优先级抢占调度。有些系统允许进程根据其行为在队列之间移动(多级反馈队列)。


12. Scheduling in Modern Operating Systems | 现代操作系统中的调度

Modern systems like Linux use completely fair scheduler (CFS), which allocates CPU time proportionally based on virtual runtime. Windows uses a priority-based preemptive scheduler with 32 priority levels. Mobile operating systems often incorporate power-aware scheduling. The focus is on responsiveness, throughput, and energy efficiency.

像 Linux 这样的现代系统使用完全公平调度器(CFS),基于虚拟运行时间按比例分配 CPU 时间。Windows 使用基于优先级的抢占式调度器,具有 32 个优先级。移动操作系统通常融合了功耗感知调度。重点是响应性、吞吐量和能效。

Published by TutorHao | Computer Science Revision Series | aleveler.com

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

Comments

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

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