此博客处内容为 《操作系统导论》(Operating Systems: Three Easy Pieces)第7章:进程调度:介绍,课后作业解析翻译,便于学习。
原书英文版地址 https://pages.cs.wisc.edu/~remzi/OSTEP/
scheduler.py 这个调度程序,允许你查看不同调度器在相应时间(response time),周转时间(turnaround time)和总等待时间等调度指标下的执行情况。程序中实现了三个调度算法:FIFO,SJF和RR。(该调度程序代码将在文章最后附上)
运行该程序需要两步:
首先,在没有 “-c” 标志的情况下运行:这将告诉你要解决什么问题,而不会给出答案。例如,计算响应时间,周转试件,并使用FIFO策略等待三个作业,那么运行如下进程:
>> python scheduler.py -p FIFO -j 3 -s 100
这指定了具有三个作业的FIFO策略,重要的是,指定了一个100的特定随机种子。如果你想知道这个问题的答案,你必须再次指定这个完全相同的随机种子。运行上述代码后得到如下结果
ARG policy FIFO
ARG jobs 3
ARG maxlen 10
ARG seed 100
Here is the job list, with the run time of each job:
Job 0 (length = 1)
Job 1 (length = 4)
Job 2 (length = 7)
Compute the turnaround time, response time, and wait time for each job. When
you are done, run this program again, with the same arguments, but with -c,
which will thus provide you with the answers. You can use -s <somenumber> or
your own job list (-l 10,15,20 for example) to generate different problems for
yourself.
从这个程序中可以看到,生成三个作业(job):长度为1的job 0,长度为4的job 1以及长度为7的job 2。现在可以使用它来计算一些统计数据,看看是否掌握了基本概念。
一旦你完成了,你可以使用相同的程序来“解决”问题,看看你是否正确地做了你的工作。为此,使用"-c"标志。
>> python scheduler.py -p FIFO -j 3 -s 100 -c
ARG policy FIFO
ARG jobs 3
ARG maxlen 10
ARG seed 100
Here is the job list, with the run time of each job:
Job 0 (length = 1)
Job 1 (leng