在eclipse下导入项目,在Main类中运行即可。若想修改测试数据,在Main类main函数下,
- 修改times数组,修改就绪态时间片。
- 修改processes修改测试进程,输入进程Id、开始时间、运行时间、阻塞开始时间、阻塞结束时间,通过PCB构造方法创建一个进程。
/* 优先级队列时间片 */
int[] times = {10, 7, 4};
PCB[] processes = {
/* 进程Id、开始时间、运行时间、阻塞开始时间、阻塞结束时间 */
new PCB("P1", 3, 23, 4, 9),
new PCB("P2", 8, 17, -1, 0),
new PCB("P3", 15, 10, 6, 2),
new PCB("P4", 15, 9, 2, 4)
};
cpuTime 0
New [P1(0, 0), P2(0, 0), P3(0, 0), P4(0, 0)]
Blocked []
Ready0 []
Ready1 []
Ready2 []
Running null
Exit []
-----------------------------
执行3,cpuTime 3
Process P1: New -> Ready0
Process P1: Ready0 -> Running
New [P2(0, 0), P3(0, 0), P4(0, 0)]
Blocked []
Ready0 []
Ready1 []
Ready2 []
Running P1(0, 0)
Exit []
-----------------------------
执行4,cpuTime 7
Process P1: Running -> Blocked
7 - 就绪队列为空
New [P2(0, 0), P3(0, 0), P4(0, 0)]
Blocked [P1(4, 0)]
Ready0 []
Ready1 []
Ready2 []
Running null
Exit []
-----------------------------
执行1,cpuTime 8
Process P2: New -> Ready0
Process P2: Ready0 -> Running
New [P3(0, 0), P4(0, 0)]
Blocked [P1(4, 1)]
Ready0 []
Ready1 []
Ready2 []
Running P2(0, 0)
Exit []
-----------------------------
执行10,cpuTime 18
Process P3: New -> Ready0
Process P4: New -> Ready0
Process P1: Blocked -> Ready1
Process P2: Running -> Ready1
Process P3: Ready0 -> Running
New []
Blocked []
Ready0 [P4(0, 0)]
Ready1 [P1(4, 11), P2(10, 0)]
Ready2 []
Running P3(0, 0)
Exit []
-----------------------------
执行6,cpuTime 24
Process P3: Running -> Blocked
Process P4: Ready0 -> Running
New []
Blocked [P3(6, 0)]
Ready0 []
Ready1 [P1(4, 11), P2(10, 0)]
Ready2 []
Running P4(0, 0)
Exit []
-----------------------------
执行2,cpuTime 26
Process P3: Blocked -> Ready1
Process P4: Running -> Blocked
Process P1: Ready1 -> Running
New []
Blocked [P4(2, 0)]
Ready0 []
Ready1 [P2(10, 0), P3(6, 2)]
Ready2 []
Running P1(4, 11)
Exit []
-----------------------------
执行7,cpuTime 33
Process P4: Blocked -> Ready1
Process P1: Running -> Ready2
Process P2: Ready1 -> Running
New []
Blocked []
Ready0 []
Ready1 [P3(6, 2), P4(2, 7)]
Ready2 [P1(11, 11)]
Running P2(10, 0)
Exit []
-----------------------------
执行7,cpuTime 40
Process P2: Running -> Exit
Process P3: Ready1 -> Running
New []
Blocked []
Ready0 []
Ready1 [P4(2, 7)]
Ready2 [P1(11, 11)]
Running P3(6, 2)
Exit [P2(17, 0)]
-----------------------------
执行4,cpuTime 44
Process P3: Running -> Exit
Process P4: Ready1 -> Running
New []
Blocked []
Ready0 []
Ready1 []
Ready2 [P1(11, 11)]
Running P4(2, 7)
Exit [P2(17, 0), P3(10, 2)]
-----------------------------
执行7,cpuTime 51
Process P4: Running -> Exit
Process P1: Ready2 -> Running
New []
Blocked []
Ready0 []
Ready1 []
Ready2 []
Running P1(11, 11)
Exit [P2(17, 0), P3(10, 2), P4(9, 7)]
-----------------------------
执行4,cpuTime 55
Process P1: Running -> Ready2
Process P1: Ready2 -> Running
New []
Blocked []
Ready0 []
Ready1 []
Ready2 []
Running P1(15, 11)
Exit [P2(17, 0), P3(10, 2), P4(9, 7)]
-----------------------------
执行4,cpuTime 59
Process P1: Running -> Ready2
Process P1: Ready2 -> Running
New []
Blocked []
Ready0 []
Ready1 []
Ready2 []
Running P1(19, 11)
Exit [P2(17, 0), P3(10, 2), P4(9, 7)]
-----------------------------
执行4,cpuTime 63
Process P1: Running -> Exit
63 - 就绪队列为空
New []
Blocked []
Ready0 []
Ready1 []
Ready2 []
Running null
Exit [P2(17, 0), P3(10, 2), P4(9, 7), P1(23, 11)]
-----------------------------
New, Ready, blocked, Running队列都为空,程序运行结束