等待时间返回到达时间大于安排算法中的突发时间时的减去值
我正在尝试在C中实现FCFS调度算法,并创建时间间隔,直到用户输入另一个过程为止。这是以下几行的代码将显示我要问的实际问题。
#include <stdio.h>
#include <time.h>
#define MAX 50
struct ProcessControlBlock{
int processID;
int burstTime;
int arrivalTime;
int turnAround;
};
void main(){
int terminateController=1;
int inputCheck;
int processIndex = 0;
struct ProcessControlBlock processControlBlocks[MAX];
time_t beginTime = time(NULL);
while(terminateController!=0){
printf("If you want to enter a process, please press 1: ");
scanf("%d",&inputCheck);
time_t endTime = time(NULL);
if(inputCheck==1){
printf("The arrival time of the process is %d\n",(endTime-beginTime));
processControlBlocks[processIndex].processID = processIndex;
processControlBlocks[processIndex].arrivalTime = endTime-beginTime;
printf("Process ID is: %d\n", processControlBlocks[processIndex].processID);
printf("Enter the burst time of the process: ");
scanf("%d",&processControlBlocks[processIndex].burstTime);
printf("Waiting time of the process is: %d\n",(processControlBlocks[processIndex].burstTime-processControlBlocks[processIndex].arrivalTime));
}
printf("If you want to continue to add process, please press 1: ");
scanf("%d",&terminateController);
processIndex++;
}
}
因此,例如,当用户等待第二个进程输入时,时间将是12秒。而且,如果过程的突发时间为8秒,等待时间将为-4秒,这没有任何意义。那么,我犯的错误是什么,或者我想念的东西是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您只对
等待时间
,计划时间
&amp;turn-around time
对于每个进程用户输入。然后也许平均等待时间
&amp;平均转移时间
。用户可能需要几秒钟才能输入
Process-details
,就像在您的情况下决定继续两次是否继续,然后输入爆发时间
。您可以实现实时仿真,但是跟踪&amp;验证这些统计数据变得乏味。相反,您为一组流程准备测试数据&amp;带有预期结果的计数。因此,我们需要事先进行详细信息:
然后,您按(到达时间&amp;入门订单)对列表进行排序,并处理每个过程计算的列表:
您将其与其他调度算法进行比较,该算法对流程的公平程度。
以下是c实施夫妇:
I think you're only interested in
wait-time
,schedule-time
&turn-around-time
for each process user inputs. Then perhapsaverage-wait-time
&average-turn-around-time
.User may take several seconds to input
process-details
, like in your case deciding to continue twice whether to continue and then enter aburst-time
.You can implement real-time simulation, but tracing & validating those statistics becomes tedious. Instead you prepare test-data for set of processes & tally with expected results. So details we need beforehand:
Then you sort the list by (arrival-time & entry-order), and process the list calculating for each process:
You compare this with other scheduling algorithms, how fair it is for the processes.
Here are couple C implementation :
FCFS调度按照先进先出原则工作,就像队列一样。进程根据到达时间添加到队列中,并根据在队列中的位置、等待时间和执行时间删除。等待时间取决于队列中前一个进程的退出时间(如果有),要计算它,您必须跟踪队列中所有进程的到达时间、执行时间和等待时间。
例子:
FCFS scheduling works on FIFO principle, just like a queue. Processes are added to the queue based on arrival time and removed based on position in the queue, waiting time and execution time. Waiting time depends on the exit time of the previous process in the queue (if any), to calculate it you have to keep track of arrival time, execution time and waiting time of all the processes in the queue.
Example: