OSTEP:进程的概念理解
第四章:进程
作业来自: ostep-homework
两个程序都只使用CPU,所以CPU的利用率是100%,测试可得:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15Time PID: 0 PID: 1 CPU IOs
1 RUN:cpu READY 1
2 RUN:cpu READY 1
3 RUN:cpu READY 1
4 RUN:cpu READY 1
5 RUN:cpu READY 1
6 DONE RUN:cpu 1
7 DONE RUN:cpu 1
8 DONE RUN:cpu 1
9 DONE RUN:cpu 1
10 DONE RUN:cpu 1
Stats: Total Time 10
Stats: CPU Busy 10 (100.00%)
Stats: IO Busy 0 (0.00%)总共使用了11 ticks的时间,测试可得:
1
2
3
4
5
6
7
8
9
10
11
12Time PID: 0 PID: 1 CPU IOs
1 RUN:cpu READY 1
2 RUN:cpu READY 1
3 RUN:cpu READY 1
4 RUN:cpu READY 1
5 DONE RUN:io 1
6 DONE WAITING 1
7 DONE WAITING 1
8 DONE WAITING 1
9 DONE WAITING 1
10 DONE WAITING 1
11* DONE RUN:io_done 1交换顺序后,在PID0进行io操作的时候,PID1会切换成RUNNING的状态,提高了CPU的利用效率,所以交换顺序重要。测试可得:
1
2
3
4
5
6
7
8Time PID: 0 PID: 1 CPU IOs
1 RUN:io READY 1
2 WAITING RUN:cpu 1 1
3 WAITING RUN:cpu 1 1
4 WAITING RUN:cpu 1 1
5 WAITING RUN:cpu 1 1
6 WAITING DONE 1
7* RUN:io_done DONE 1由于加上了
SWITCH_ON_END
的标签,此时PID0进行IO操作的时候CPU会空闲等待至IO操作完成,浪费了一定的时间。测试可得:1
2
3
4
5
6
7
8
9
10
11
12Time PID: 0 PID: 1 CPU IOs
1 RUN:io READY 1
2 WAITING READY 1
3 WAITING READY 1
4 WAITING READY 1
5 WAITING READY 1
6 WAITING READY 1
7* RUN:io_done READY 1
8 DONE RUN:cpu 1
9 DONE RUN:cpu 1
10 DONE RUN:cpu 1
11 DONE RUN:cpu 1由于这次会在等待IO的时候进行进程的切换,所以在io操作时,CPU没有等待,而是切换到了另外一个进程上继续工作,提高了利用率。测试可得:
1
2
3
4
5
6
7
8Time PID: 0 PID: 1 CPU IOs
1 RUN:io READY 1
2 WAITING RUN:cpu 1 1
3 WAITING RUN:cpu 1 1
4 WAITING RUN:cpu 1 1
5 WAITING RUN:cpu 1 1
6 WAITING DONE 1
7* RUN:io_done DONE 1由于IO操作的优先级不是最高的,即使io操作的WAITING结束了,也会等待CPU先将其他进程执行之后,再对IO进行切换,由于IO操作需要消耗比较多的额外时间,而这部分时间没有被CPU利用,所以系统资源没有得到有效利用。测试可得:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32Time PID: 0 PID: 1 PID: 2 PID: 3 CPU IOs
1 RUN:io READY READY READY 1
2 WAITING RUN:cpu READY READY 1 1
3 WAITING RUN:cpu READY READY 1 1
4 WAITING RUN:cpu READY READY 1 1
5 WAITING RUN:cpu READY READY 1 1
6 WAITING RUN:cpu READY READY 1 1
7* READY DONE RUN:cpu READY 1
8 READY DONE RUN:cpu READY 1
9 READY DONE RUN:cpu READY 1
10 READY DONE RUN:cpu READY 1
11 READY DONE RUN:cpu READY 1
12 READY DONE DONE RUN:cpu 1
13 READY DONE DONE RUN:cpu 1
14 READY DONE DONE RUN:cpu 1
15 READY DONE DONE RUN:cpu 1
16 READY DONE DONE RUN:cpu 1
17 RUN:io_done DONE DONE DONE 1
18 RUN:io DONE DONE DONE 1
19 WAITING DONE DONE DONE 1
20 WAITING DONE DONE DONE 1
21 WAITING DONE DONE DONE 1
22 WAITING DONE DONE DONE 1
23 WAITING DONE DONE DONE 1
24* RUN:io_done DONE DONE DONE 1
25 RUN:io DONE DONE DONE 1
26 WAITING DONE DONE DONE 1
27 WAITING DONE DONE DONE 1
28 WAITING DONE DONE DONE 1
29 WAITING DONE DONE DONE 1
30 WAITING DONE DONE DONE 1
31* RUN:io_done DONE DONE DONE 1在使用了IMMEDIATE标签后,每次io_done之后CPU都会先切换io操作,然后用io处理的时间来处理其他进程,提高了系统资源的利用率。测试如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22Time PID: 0 PID: 1 PID: 2 PID: 3 CPU IOs
1 RUN:io READY READY READY 1
2 WAITING RUN:cpu READY READY 1 1
3 WAITING RUN:cpu READY READY 1 1
4 WAITING RUN:cpu READY READY 1 1
5 WAITING RUN:cpu READY READY 1 1
6 WAITING RUN:cpu READY READY 1 1
7* RUN:io_done DONE READY READY 1
8 RUN:io DONE READY READY 1
9 WAITING DONE RUN:cpu READY 1 1
10 WAITING DONE RUN:cpu READY 1 1
11 WAITING DONE RUN:cpu READY 1 1
12 WAITING DONE RUN:cpu READY 1 1
13 WAITING DONE RUN:cpu READY 1 1
14* RUN:io_done DONE DONE READY 1
15 RUN:io DONE DONE READY 1
16 WAITING DONE DONE RUN:cpu 1 1
17 WAITING DONE DONE RUN:cpu 1 1
18 WAITING DONE DONE RUN:cpu 1 1
19 WAITING DONE DONE RUN:cpu 1 1
20 WAITING DONE DONE RUN:cpu 1 1
21* RUN:io_done DONE DONE DONE 1开放题随机,和前七题大致相同。
OSTEP:进程的概念理解
https://halc.top/p/e328a303