【LittleXi】Chapter 4 Process Intro exercise

【LittleXi】Chapter 4 Process Intro exercise

Chapter Four

Experiment preparation

  • Download the code required for the experiment

wget http://pages.cs.wisc.edu/~remzi/OSTEP/Homework/HW-CPU-Intro.tgz

  • Unzip

tar -zxvf HW-CPU-Intro.tgz

  • Note that you must use python2

sudo apt-get update && sudo apt-get install python2

question

1. Run the program with the following flags: ./process-run.py -l 5:100,5:100. What should the CPU utilization (percentage of CPU time used) be? Why do you know this? Use the -c flag to see if your answer is correct.

Answer: python2 ./process-run.py -l 5:100,5:100Judging from the running screenshots, the CPU utilization should be 100%, because the running process Process 1 is not running.

Please add image description

Verify the answer, it is indeed correctpython2 ./process-run.py -l 5:100,5:100 -c

Please add image description

2. Now run with these flags: ./process-run.py -l 4:100,1:0. These flags specify a process that consists of 4 instructions (all using the CPU) and simply issues I/O and waits for it to complete. How long does it take to complete both processes? Use -c to check that your answer is correct.

Answer: When running python2 ./process-run.py -l 4:100,1:0, the time consumed to complete process 0 is 4 CPU times. The completion time of the second process cannot be confirmed, because from the printed results, process 1 only outputs, ioand the CPU time consumed cannot be completely determined.

Please add image description

Further running python2 ./process-run.py -l 4:100,1:0 -ccan be found that process 0 is consistent with our answer. The io of process 2 is occupied once, then 4 CPU times are blocked, and the last CPU time completes the process.

Please add image description

3.Now swap the order of the processes: ./process-run.py -l 1:0,4:100. What's happening now? Does the order of exchange matter? Why? Again, use -c to see if your answer is correct.

Answer: python2 ./process-run.py -l 1:0,4:100After running, it is found that processes 0 and 1 have exchanged the running order. The importance of the exchange order is temporarily unclear.

Please add image description

After running python2 ./process-run.py -l 1:0,4:100 -c, I found that it is very important to swap the order of processes, because as you can see here, process 0 does not occupy the CPU time when it is blocked, but gives the CPU time to process 1, which greatly saves the completion of the two processes. total time

Please add image description

4.Now explore some more signs. An important flag is -S, which determines how the system reacts when a process issues I/O. By setting the flag to SWITCH_ON_END, the system will not switch to another process while the process is performing I/O operations, but will wait for the process to complete. What happens when you run the following two processes? One performs I/O and the other performs CPU work. (-l 1:0,4:100 -c -S SWITCH_ON_END)

Answer: Run python2 ./process-run.py -l 1:0,4:100 -c -S SWITCH_ON_END, after setting the flag to SWITCH_ON_END, process 0 will always occupy CPU time, extending the total running time.

Please add image description

5. Now, run the same process, but switch the behavior settings to switch to another process while waiting for I/O (-l 1:0,4:100 -c -S SWITCH_ON_IO). What happens now? Use -c to confirm your answer is correct.

Answer: Run python2 ./process-run.py -l 1:0,4:100 -c -S SWITCH_ON_IO, after setting the flag to SWITCH_ON_IO, the CPU usage will be released when process 0 is blocked, the same as the default situation

Please add image description

6. Another important behavior is what to do when the I/O is complete. With -I IO_RUN_LATER, when the I/O is completed, the process that issued it may not run immediately. Instead, the process running at that time keeps running. What happens when you run this combination of processes? (./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 used effectively?

Answer: Run python2 process-run.py -l 3:0,5:100,5:100,5:100 -S SWITCH_ON_IO -I IO_RUN_LATER -c -p, you can find that after completing the IO, when the CPU is not idle, the process will not run immediately

Please add image description

7. Now run the same process, but with the -I IO_RUN_IMMEDIATE setting, which immediately runs the process that issued the I/O. How is this behavior different? Why is it a good idea to run a process that has just completed I/O?

Answer: Run python2 process-run.py -l 3:0,5:100,5:100,5:100 -S SWITCH_ON_IO -I IO_RUN_IMMEDIATE -c -p, just as we set, the CPU will directly occupy the CPU time after completing the IO stream.

Please add image description

8. Now run some randomly generated processes, for example, -s 2 -l 3:50,3:50, -s 3 -l 3:50,3:50. See if you can predict how the track record will change? What happens when you use -I IO_RUN_IMMEDIATE with -I IO_RUN_ LATER? What happens when you use -S SWITCH_ON_IO with -S SWITCH_ON_END?

Answer: The generality of running randomly generated processes is similar to the prediction. After SWITCH_ON_IO and IO_RUN_IMMEDIATE are turned on, the overall CPU usage will increase significantly, and the IO rate will also increase significantly (because the total time spent is reduced)
Please add image description

Guess you like

Origin blog.csdn.net/qq_68591679/article/details/133126231