首页 > 编程知识 正文

fcfs调度算法等待时间怎么求,fcfs调度算法优点

时间:2023-05-03 11:44:53 阅读:215552 作者:3426

fcfs调度算法

Here you will get C/C++ program for first come first served (fcfs) scheduling algorithm.

在这里,您将获得用于先到先得(fcfs)调度算法的C / C ++程序。

What is First Come First Served (FCFS) Scheduling Algorithm?

什么是先来先服务(FCFS)调度算法?

First Come First Served (FCFS) is a Non-Preemptive scheduling algorithm. FIFO (First In First Out) strategy assigns priority to process in the order in which they request the processor. The process that requests the CPU first is allocated the CPU first. This is easily implemented with a FIFO queue for managing the tasks. As the process come in, they are put at the end of the queue. As the CPU finishes each task, it removes it from the start of the queue and heads on to the next task.

先来先服务(FCFS)是一种非抢先式调度算法。 FIFO(先进先出)策略按请求处理器的顺序分配处理优先级。 首先请求CPU的进程将首先分配CPU。 这可以通过用于管理任务的FIFO队列轻松实现。 随着过程的进行,它们被放在队列的末尾。 CPU完成每个任务时,会将其从队列开始处删除,然后转到下一个任务。

Also Read: C Program for Shortest Job First (SJF) Scheduling Algorithm

另请阅读: 最短作业优先(SJF)调度算法的C程序

C程序 (C Program) #include<stdio.h> int main(){    int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;    printf("Enter total number of processes(maximum 20):");    scanf("%d",&n);     printf("nEnter Process Burst Timen");    for(i=0;i<n;i++)    {        printf("P[%d]:",i+1);        scanf("%d",&bt[i]);    }     wt[0]=0;    //waiting time for first process is 0     //calculating waiting time    for(i=1;i<n;i++)    {        wt[i]=0;        for(j=0;j<i;j++)            wt[i]+=bt[j];    }     printf("nProcessttBurst TimetWaiting TimetTurnaround Time");     //calculating turnaround time    for(i=0;i<n;i++)    {        tat[i]=bt[i]+wt[i];        avwt+=wt[i];        avtat+=tat[i];        printf("nP[%d]tt%dtt%dtt%d",i+1,bt[i],wt[i],tat[i]);    }     avwt/=i;    avtat/=i;    printf("nnAverage Waiting Time:%d",avwt);    printf("nAverage Turnaround Time:%d",avtat);     return 0;} C ++程序 (C++ Program) #include<iostream> using namespace std; int main(){    int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;    cout<<"Enter total number of processes(maximum 20):";    cin>>n;     cout<<"nEnter Process Burst Timen";    for(i=0;i<n;i++)    {        cout<<"P["<<i+1<<"]:";        cin>>bt[i];    }     wt[0]=0;    //waiting time for first process is 0     //calculating waiting time    for(i=1;i<n;i++)    {        wt[i]=0;        for(j=0;j<i;j++)            wt[i]+=bt[j];    }     cout<<"nProcessttBurst TimetWaiting TimetTurnaround Time";     //calculating turnaround time    for(i=0;i<n;i++)    {        tat[i]=bt[i]+wt[i];        avwt+=wt[i];        avtat+=tat[i];        cout<<"nP["<<i+1<<"]"<<"tt"<<bt[i]<<"tt"<<wt[i]<<"tt"<<tat[i];    }     avwt/=i;    avtat/=i;    cout<<"nnAverage Waiting Time:"<<avwt;    cout<<"nAverage Turnaround Time:"<<avtat;     return 0;} Comment below if you found anything incorrect or missing in above fcfs program in C and C++. 如果在C和C ++中的上述fcfs程序中发现任何不正确或丢失的内容,请在下面评论。

翻译自: https://www.thecrazyprogrammer.com/2014/11/c-cpp-program-for-first-come-first-served-fcfs.html

fcfs调度算法

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。