过程数据:
进程{CPU突发,I / O时间,CPU突发,I / O时间,CPU突发,I / O时间,......,最后一次CPU突发}
我将数据拆分为两个数组。 cpu burst和io_burst
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}
我大部分时间都在计算等待时间。我在这里做了一个课程
class Process
{
//public Process(string name, int arrival, int cpuburst,int ioburst, int priority)
//{
// this.name = name;
// this.arrival = arrival;
// this.cpuburst = cpuburst;
// this.ioburst = ioburst;
// this.priority = priority;
//}
public Process()
{
}
public string name;
public int arrival;
public int[] cpuburst;
public int []ioburst;
public int priority;
public int totburst;
public int wait;
public int end;
public int start;
public int contextswitch;
public int response;
public int turnAround;
//public int contextswitch;
public double cpu_utilization;
public double avwaitingtime;
public double avturnaroundtime;
public double avresponse;
}
}
继承人我是如何初始化的,我通过在数组的末尾添加一些零来使cpuburst和io_burst具有相同的大小
void initialize_process()
{
List<Process> processes = new List<Process>();
Process p1 = new Process();
p1.arrival = 0;
p1.end = 0;
p1.name = "P1";
p1.cpuburst = new int[] { 4, 5, 3, 5, 4, 6, 4, 5, 2 ,0};
p1.ioburst = new int[] { 24, 73, 31, 27, 33, 43, 64, 19, 0, 0 };
p1.totburst = 38;
processes.Add(p1);
Process p2 = new Process();
p2.arrival = 0;
p2.name = "P2";
p2.end = 0;
p2.cpuburst = new int[] { 18, 19, 11, 18, 19, 18, 17, 19, 10, 0 };
p2.ioburst = new int[] { 31, 35, 42, 43, 47, 43, 51, 32, 0, 0 };
p2.totburst = 149;
processes.Add(p2);
Process p3 = new Process();
p3.arrival = 0;
p3.end = 0;
p3.name = "P3";
p3.cpuburst = new int[]{ 6, 4, 7, 4, 5, 7, 8, 6, 5 ,0};
p3.ioburst = new int[] { 18, 21, 19, 16, 29, 21, 22, 24, 0, 0 };
p3.totburst = 52;
processes.Add(p3);
Process p4 = new Process();
p4.arrival = 0;
p4.end = 0;
p4.name = "P4";
p4.cpuburst = new int[] { 17, 19, 20, 17, 15, 12, 15, 14,0,0 };
p4.ioburst = new int[] { 42, 55, 54, 52, 67, 72, 66, 0, 0, 0 };
p4.totburst = 129;
processes.Add(p4);
Process p5 = new Process();
p5.arrival = 0;
p5.end = 0;
p5.name = "P5";
p5.cpuburst = new int[]{ 5, 4, 5, 3, 5, 4, 3, 4, 3, 5 };
p5.ioburst = new int[] { 81, 82, 71, 61, 62, 51, 77, 61, 42, 0 };
p5.totburst = 41;
processes.Add(p5);
Process p6 = new Process();
p6.arrival = 0;
p6.end = 0;
p6.name = "P6";
p6.cpuburst = new int[] { 10, 12, 14, 11, 15, 13, 11,0,0,0 };
p6.ioburst = new int[] { 35, 41, 33, 32, 41, 29, 0, 0, 0, 0 };
p6.totburst = 86;
processes.Add(p6);
Process p7 = new Process();
p7.arrival = 0;
p7.end = 0;
p7.name = "P7";
p7.cpuburst = new int[]{ 21, 23, 24, 22, 21, 20,0,0,0,0 };
p7.ioburst = new int[] { 51, 53, 61, 31, 43, 0, 0, 0, 0, 0 };
p7.totburst = 131;
processes.Add(p7);
Process p8 = new Process();
p8.arrival = 0;
p8.end = 0;
p8.name = "P8";
p8.cpuburst = new int[] { 11, 14, 15, 17, 16, 12, 13, 15, 0, 0 };
p8.ioburst = new int[] { 52, 42, 31, 21, 43, 31, 32, 0, 0, 0 };
p8.totburst = 113;
processes.Add(p8);
FCFS(processes);
SJF(processes);
}
在我的FCFS函数中,我调用其他函数来执行计算
void FCFS(List<Process> p)
{
output.Items.Add("After FCFS");
output.Items.Add("-------------------------------------------------------");
wait(p);
turnaroundtime(p);
responsetime(p);
completeoutputlist(p);
}
我在等待时间的尝试失败了,我真的不知道如何最好地接近这一点。我想在这里计算这些值,然后我可以在其他函数中调用它们。 在计算时钟时,我主要考虑如何考虑I / O时间
进程在运行其他进程的同时进行I / O操作。因此,I / O应该递减,因为每个进行I / O的进程的计时器都会递增。 多个进程可以同时进行i / o。所以你需要一个正在进行i / o的进程列表。 真的只需要这方面的一些指导。
void wait(List<Process> p)
{
/* Goal keep track of context switches. - p.contextswitch
* Keep track of the first time it enters to get response time - p.start
* Keep track of when the process ends - so later we can calc turnaround time p.end
* then tweak some functions so it works again
*
*/
}
在我做这样的事之前
void wait(List<Process> p)
{
/* Goal keep track of context switches. - p.contextswitch
* Keep track of the first time it enters to get response time - p.start
* Keep track of when the process ends - so later we can calc turnaround time p.end
* then tweak some functions so it works again
*
*/
int k = 0;
int i = 0;
int clock = 0;
int contextswitch = 0;
int cpuready = 0;
int ioready = 0;
double avwaitingtime = 0;
for (k = 0; k < 10; k++)
{
for (i = 0; i < p.Count; i++)
{
//cpuready = p[i].cpuburst[k];
//ioready = p[i].ioburst[k];
clock += p[i].cpuburst[k];
//sets arrival time P1
if (i == 0 && k == 0)
{
p[0].arrival = 0;
}
//sets arrival time P2
if (i == 1 && k == 0)
{
p[1].arrival = clock;
}
//sets arrival time P3
if (i == 2 && k == 0)
{
p[2].arrival = clock;
}
//sets arrival time P4
if (i == 3 && k == 0)
{
p[3].arrival = clock;
}
//sets arrival time P5
if (i == 4 && k == 0)
{
p[4].arrival = clock;
}
//sets arrival time P6
if (i == 5 && k == 0)
{
p[5].arrival = clock;
}
//sets arrival time P7
if (i == 6 && k == 0)
{
p[6].arrival = clock;
}
//sets arrival time P8
if (i == 7 && k == 0)
{
p[7].arrival = clock;
}
//ADDS TO THE CONTEXT SWITCH CONTER
contextswitch += 1;
//Checks the first row and the last column
if (i == 0 && k == 8)
{
p[0].end = clock;
}
//Checks the 2nd row and the last column
if (i == 1 && k == 8)
{
p[1].end = clock;
}
//Checks the 3rd row and the last column
if (i == 2 && k == 8)
{
p[2].end = clock;
}
//Checks the 4th row and the last column
if (i == 3 && k == 7)
{
p[3].end = clock;
}
//Checks the 5th row and the last column
if (i == 4 && k == 9)
{
p[4].end = clock;
}
//Checks the 6th row and the last column
if (i == 5 && k == 6)
{
p[5].end = clock;
}
//Checks the 7th row and the last column
if (i == 6 && k == 5)
{
p[6].end = clock;
}
//Checks the 8th row and the last column
if (i == 7 && k == 7)
{
p[7].end = clock;
}
}
}
output.Items.Add(clock);
double waitsum = 0;
for (i = 0; i < 8; i++)
{
//CALCS THE WAIT TIME
p[i].wait = (p[i].end- p[i].totburst);
// output.Items.Add(p[i].wait);
//CALCS THE WAITSUM
waitsum += p[i].wait;
}
//calcs avg wait time
avwaitingtime = (waitsum / 8.0);
//output.Items.Add(avg);
output.Items.Add(contextswitch);
cpu_utilization(p, contextswitch,clock);
for (i = 0; i < 8; i++)
{
p[i].avwaitingtime = avwaitingtime;
}
}
关于如何处理这个问题的任何想法都会有很多帮助,谢谢!