附件 2
摘 要
进程是程序的执行,该程序执行该程序中指定的动作。可以将其定义为程序
在其中运行的执行单元。该操作系统可帮助您创建,安排和终止 CPU 使用的进程。
由主流程创建的流程称为子流程。借助 PCB(过程控制块)可以轻松控制过程操
作。您可以将其视为进程的大脑,其中包含与处理相关的所有关键信息,例如进
程 ID,优先级,状态,CPU 寄存器等
OS 利用“进程实体”控制程序执行就产生了“进程”。进程是实体的运行过
程,是系统进行资源分配和调度的一个独立单位;具有动态性、并发性、独立性、
异步性特性。
进程的基本状态:(进程执行的间断性决定了其具有多种状态。把握各进程
所属的状态对进程控制至关重要。与进程执行相关的各种共享资源有:CPU、存
储器、I/O 设备、时间片) 所以进程的三种基本状态有:就绪状态、运行状态、
阻塞状态。
使用算法在队列上实现先进先出,实现了基本的算法调度,效果是按照顺序
执行。FIFO 算法维护一个先进先出队列,是一种最简单的调度算法。
关键词:进程管理;FIFO;调度算法
Abstract
A process is the execution of a program that performs the actions specified in the
program. It can be defined as the unit of execution in which the program runs. This
operating system helps you create, schedule, and terminate processes used by your CPU.
Processes created by a master process are called subprocesses. Process operations can
be easily controlled with the help of PCBs (Process Control Blocks). You can think of
it as the brain of a process, which contains all the key information related to processing,
such as process ID, priority, status, CPU registers, etc
The OS uses the "process entity" to control program execution, resulting in a "process".
A process is the running process of an entity and an independent unit of the system for
resource allocation and scheduling; It has the characteristics of dynamic, concurrent,
independent, and asynchronous.
Basic state of the process: (The intermittent nature of process execution determines that
it has multiple states.) Knowing the state to which each process belongs is critical to
process control. Various shared resources related to process execution are: CPU,
memory, I/O devices, time slices) So the three basic states of a process are: ready,
running, and blocking.
The algorithm is used to implement first-in-first-out on the queue, and basic algorithm
scheduling is realized, and the effect is executed sequentially. The FIFO algorithm
maintains a first-in-first-out queue and is the simplest scheduling algorithm.
Keywords: Process Management;FIFO;Scheduling algorithm
目录
第 1 章 需求分析和任务定义 ........................................................................................................................1
1.1 需求分析 .......................................................................................................................................................1
1.2 任务定义 .......................................................................................................................................................1
第 2 章 概要设计 ...............................................................................................................................................1
2.1 相关理论知识及工作原理 .......................................................................................................................1
2.1.1 Linux 的进程调度 ..............................................................................................................1
2.1.2 Linux 进程调度时机..........................................................................................................1
2.1.3 Linux 进程调度策略..........................................................................................................2
2.2 FIFO 算法介绍............................................................................................................................................3
2.2.1 FIFO 定义 ..............................................................................................................................3
2.2.2 FIFO 功能 ..............................................................................................................................3
2.2.3 FIFO 分类 ..............................................................................................................................3
2.3 问题描述和算法思想 ......................................................................................................................3
2.4 程序流程图 ...............................................................................................................................4
第 3 章 详细设计 ...............................................................................................................................................4
3.1 运行环境和编程工具.............................................................................................................4
3.2 模块划分及关系 ......................................................................................................................5
3.3 程序源代码 ...............................................................................................................................5
第 4 章 程序实现及测试 ...............................................................................................................................11
4.1 程序实现与测试.....................................................................................................................11
4.2 结果分析 .................................................................................................................................12
总结......................................................................................................................................................................12
参考文献.............................................................................................................................................................13
致 谢 .................................................................................................................................................................14
1
第 1 章 需求分析和任务定义
1.1 需求分析
在进程管理中,算法的应用场景在需要进程按照调用顺序调度的情况下使用。
算法的作用是维护一个先进先出的队列;效果是保证进程按照调用顺序执行。
1.2 任务定义
算法的实现可以分成的步骤有哪些?或者接下来的课程设计工作分哪些步
骤去完成。
1. 循环读取输入的命令
2. 通过 execvp 装载程序到子进程
3. 通过 PCB 以及 fifo 队列维护控制进程调度
第 2 章 概要设计
2.1 相关理论知识及工作原理
2.1.1 Linux 的进程调度
Linux 支持多进程,进程控制块 PCB(Process Control Block)是系统中最
为重要的数据结构之一,用来存放进程所必需的各种信息,PCB 用结构 task-
struct 来表示,包括进程的类型、进程状态、优先级、时钟信息等,Linux 系统中,
进程调度操作由 schedule()函数执行,这是一个只在内核态运行的函数,函数代
码为所有进程共享。
2.1.2 Linux 进程调度时机
Linux 的进程调度时机与现代操作系统中的调度时机基本一致,为了判断是
否可以执行内核的进程调度程序来调度进程.Linux 中设置了进程调度标志
need-resched,当标志为 1 时,可执行调度程序通常,Linux 调度时机分以下两种
情况:
(1)主动调度:指显式调用 schedule()函数明确释放 CPU,引起新一轮调
度.一般发生在当前进程状态改变,如:进程终止、进程睡眠、进程对某些信号
处理过程中等。
(2)被动调度:指不显示调用 schedule()函数,只是 PCB 中的 need-resched
进程调度标志,该域置位为 1 将引起新的进程调度,而每当中断处理和系统调用