实现FCFS CPU调度算法

时间:2013-10-16 19:31:53

标签: c++

我获得了实施FCFS,SJF和MLFQ的任务。我目前正在尝试使用FCFS。算法我理解它是如何使用的。我坚持的部分是创建一个实现此算法的C ++程序。我得到了一个特定的cpu突发,以及我必须实现的I / O时间。我有8个进程,每个进程有多个cpu突发和I / O时间。看起来像这样。

P1 {4,24,5,73,3,31,5,27,4,33,6,43,4,64,5,19,2}
P2 {18,31,19,35,11,42,18,43,19,47,18,43,17,51,19,32,10}
P3 {6,18,4,21,7,19,4,16,5,29,7,21,8,22,6,24,5}
P4 {17,42,19,55,20,54,17,52,15,67,12,72,15,66,14}
P5 {5,81,4,82,5,71,3,61,5,62,4,51,3,77,4,61,3,42,5}
P6 {10,35,12,41,14,33,11,32,15,41,13,29,11}
P7 {21,51,23,53,24,61,22,31,21,43,20}
P8 {11,52,14,42,15,31,17,21,16,43,12,31,13,32,15}</code>

the order is cpu burst, i/o time, cpu burst, i/o, etc...

Here is how the output should be.

Current Time: 0

Now Running: P1

Ready Queue:   Process    Burst
                  P2        18
                  P3         6
                  P4        17
                  P5         5
                  P6        10
                  P7        21
                  P8        11
Now In I/O:    Process    Remaining time
                [empty]

Current Time: 4

Now running: P2

Ready queue:   Process    Burst
                P3          6
                P4          17
                P5          5
                P6          10
                P7          21
                P8          11

Now in I/O:    Process    Remaining time
                 P1         24

P1 {4,24,5,73,3,31,5,27,4,33,6,43,4,64,5,19,2} P2 {18,31,19,35,11,42,18,43,19,47,18,43,17,51,19,32,10} P3 {6,18,4,21,7,19,4,16,5,29,7,21,8,22,6,24,5} P4 {17,42,19,55,20,54,17,52,15,67,12,72,15,66,14} P5 {5,81,4,82,5,71,3,61,5,62,4,51,3,77,4,61,3,42,5} P6 {10,35,12,41,14,33,11,32,15,41,13,29,11} P7 {21,51,23,53,24,61,22,31,21,43,20} P8 {11,52,14,42,15,31,17,21,16,43,12,31,13,32,15}</code>

我在想我必须使用双向链表来实现这一目标。该程序仅在有上下文切换时才输出此信息。我不确定我应该从哪里开始。我想到的事情就是创建一个结构或类。但我不太确定

0 个答案:

没有答案