• 第4章 抽象:进程


    Homework

            This program, process-run.py, allows you to see how process states change as programs run and either use the CPU (e.g., perform an add instruction) or do I/O (e.g., send a request to a disk and wait for it to complete). See the README for details.

    Questions:

     1. Run process-run.py with the following flags: -l 5:100,5:100. What should the CPU utilization be (e.g., the percent of time the CPU is in use?) Why do you know this? Use the -c and -p flags to see if you were right.

    python process-run.py -l 5:100,5:100 -c -p

     2. Now run with these flags: ./process-run.py -l 4:100,1:0. These flags specify one process with 4 instructions (all to use the CPU), and one that simply issues an I/O and waits for it to be done. How long does it take to complete both processes? Use -c and -p to find out if you were right 

    python process-run.py -l 4:100,1:0 -c -p

    3. Switch the order of the processes: -l 1:0,4:100. What happens now? Does switching the order matter? Why? (As always, use -c and -p to see if you were right)

    交换顺序减少了总运行时间,提高了CPU和I/O的利用率,因为实现了重叠(overlap)

    python process-run.py -l 1:0,4:100 -c -p

     4. We’ll now explore some of the other flags. One important flag is -S, which determines how the system reacts when a process issues an I/O. With the flag set to SWITCH ON END, the system will NOT switch to another process while one is doing I/O, instead waiting until the process is completely finished. What happens when you run the following two processes (-l 1:0,4:100 -c -S SWITCH ON END), one doing I/O and the other doing CPU work?

     使用 SWITCH_ON_END,系统不会切换到另一个进程,而PID 1的进程将一直处于READY

    python process-run.py -l 1:0,4:100 -S SWITCH_ON_END -c -p 

     5. Now, run the same processes, but with the switching behavior set to switch to another process whenever one is WAITING for I/O (-l 1:0,4:100 -c -S SWITCH ON IO). What happens now? Use -c and -p to confirm that you are right.

    使用 SWITCH_ON_IO,系统会切换到另一个进程

    python process-run.py -l 1:0,4:100 -S SWITCH_ON_IO -c -p

     6. One other important behavior is what to do when an I/O completes. With -I IO RUN LATER, when an I/O completes, the process that issued it is not necessarily run right away; rather, whatever was running at the time keeps running. What happens when you run this combination of processes? (Run ./process-run.py -l 3:0,5:100,5:100,5:100 -S SWITCH ON IO -I IO RUN LATER -c -p) Are system resources being effectively utilized?

     python process-run.py -l 3:0,5:100,5:100 -S SWITCH_ON_IO -I IO_RUN_LATER -c -p

     7. Now run the same processes, but with -I IO RUN IMMEDIATE set, which immediately runs the process that issued the I/O. How does this behavior differ? Why might running a process that just completed an I/O again be a good idea?

    当I/O完成时,立即运行发出它的进程,这种选择会好一些

    因为你不知道这个进程会不会又去发出I/O

    python process-run.py -l 3:0,5:100,5:100 -S SWITCH_ON_IO -I IO_RUN_IMMEDIATE -c -p

     8. Now run with some randomly generated processes: -s 1 -l 3:50,3:50 or -s 2 -l 3:50,3:50 or -s 3 -l 3:50,3:50. See if you can predict how the trace will turn out. What happens when you use the flag -I IO RUN IMMEDIATE vs. -I IO RUN LATER? What happens when you use -S SWITCH ON IO vs. -S SWITCH ON END?

    python process-run.py -s 1 -l 3:50,3:50 -S SWITCH_ON_END -c -p

     

    python process-run.py -s 2 -l 3:50,3:50 -c -p

     

    python process-run.py -s 3 -l 3:50,3:50 -c -p

  • 相关阅读:
    Cygwin工具制作Redis服务端Window版本
    二叉树入门算法题详解
    竞赛选题 基于大数据的社交平台数据爬虫舆情分析可视化系统
    基于SSM的学生事务处理系统设计与实现
    JAVA在线课程教学大纲系统计算机毕业设计Mybatis+系统+数据库+调试部署
    计算机网络选择题笔记
    Seata 源码篇之AT模式启动流程 - 中 - 03
    JAVA毕业设计教师业绩考核和职称评审系统计算机源码+lw文档+系统+调试部署+数据库
    【前端】JavaScript-事件高级
    Windows操作系统基础-第03课-DNS服务介绍
  • 原文地址:https://blog.csdn.net/suitaox26456/article/details/127429295