fcfs调度算法_C / C ++程序用于先到先得(FCFS)调度算法

本文介绍了先来先服务(FCFS)调度算法,这是一种非抢占式的调度策略,按照进程请求CPU的顺序分配。C/C++程序示例展示了如何通过FIFO队列管理任务,新进程加入队列尾部,CPU按顺序处理任务。
摘要由CSDN通过智能技术生成

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 Time\n");
    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("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround 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]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
    }
 
    avwt/=i;
    avtat/=i;
    printf("\n\nAverage 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 Time\n";
    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<<"\nProcess\t\tBurst Time\tWaiting Time\tTurnaround 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<<"]"<<"\t\t"<<bt[i]<<"\t\t"<<wt[i]<<"\t\t"<<tat[i];
    }
 
    avwt/=i;
    avtat/=i;
    cout<<"\n\nAverage Waiting Time:"<<avwt;
    cout<<"\nAverage Turnaround Time:"<<avtat;
 
    return 0;
}
C/C++ Program for First Come First Served (FCFS) Scheduling Algorithm
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调度算法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值