First come first service (FCFS) scheduling algorithm

Source: Internet
Author: User

#include <stdio.h>#defineN 5structjcb{intName//Process Name    intAtime//Process Arrival Time    intRuntime//Process Run Time    intFtime;//Process Finish Time    intTotal//Turnaround Time    floatWelght;//weighted turnaround time (turnover factor)    intArun//Process arrives Run}f[n];//start execution time, time of completion of each job, turnaround time and time of ownership turnaround (turnover factor). voidMain () {intamount; inti,j,l,k,h; structJCB F[n]; printf ("Please enter the number of processes (2-24): \ n"); scanf ("%d",&amount);  for(i=0; i<amount;i++) {printf ("Please enter the process name, process arrival time (0-30), Process run time (1-8): \ n"); scanf ("%d",&f[i].name); scanf ("%d",&f[i].atime); scanf ("%d",&f[i].runtime); } printf ("process name \ t process arrival time \ t process run time \ n");  for(i=0; i<amount;i++) {printf ("%d\t%d\t\t%d\t\n", F[i].name,f[i].atime,f[i].runtime); } printf ("------First-come-first service (FCFS) scheduling algorithm------\ n");  for(i=0; i<amount-1; i++)//sequencing by process arrival time{//If two processes arrive at the same time, press ENTER first on the screen to run         for(j=i+1; j<amount;j++)        {             if(F[j].atime <f[i].atime) {L=F[j].atime; H=F[j].runtime; K=F[j].name; F[j].atime=F[i].atime; F[j].runtime=F[i].runtime; F[j].name=F[i].name; F[i].atime=M; F[i].runtime=h; F[i].name=K; }}} printf ("Order of arrival time by process \ n"); printf ("process name \ t process arrival time \ t process run time \ n");  for(i=0; i<amount;i++) {printf ("%d\t%d\t\t%d\t\n", F[i].name,f[i].atime,f[i].runtime); } printf ("Process name process reaches start run process run process end turnaround factor \ n"); f[0].arun=0;  for(i=0; i<amount;i++)    {        if(f[i].arun<f[i].atime) {F[i].arun=F[i].atime; } f[i].ftime=f[i].arun+F[i].runtime; F[i].total=f[i].ftime-F[i].atime; F[i].welght=(float) f[i].total/(float) F[i].runtime; printf ("%d\t%d\t%d\t%d\t%d\t\t%d\t%f\n", F[i].name,f[i].atime,f[i].arun,f[i].runtime,f[i].ftime,f[i].total,f[i].welght); F[i+1].arun=f[i].arun+F[i].ftime; }}

First come first service (FCFS) scheduling algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.