Important alert: (current site time 10/31/2014 3:25:10 PM EDT)
 

VB icon

First Come First Served(FCFS)

Email
Submitted on: 10/22/2007 2:43:22 PM
By: Adri Jovin  
Level: Advanced
User Rating: By 2 Users
Compatibility: C
Views: 30927
author picture
(About the author)
 
     This is used for implementing the FCFS scheduling algorithm which is used in CPU Scheduling especially in Operatng Systems.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: First Come First Served(FCFS)
// Description:This is used for implementing the FCFS scheduling algorithm which is used in CPU Scheduling especially in Operatng Systems.
// By: Adri Jovin
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=11767&lngWId=3//for details.//**************************************

//Source code produced by Adri Jovin.J.J
#include<stdio.h>
main()
{
float avgwt,avgtt;
char pname[10][10],c[10][10];
int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;
printf("\n\nEnter the number of processes:");
scanf("%d",&n);
printf("\n\n Enter the NAME, BURST TIME and ARRIVAL TIME of thr process");
for(i=0;i<n;i++)
{
printf("\n\nNAME : ");
scanf("%s",&pname[i]);
printf("\n\nBURST TIME : ");
scanf("%d",&bt[i]);
printf("\n\n ARRIVAL TIME :");
scanf("%d",&at[i]);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(at[i]>at[j])
{
t=at[i];
at[i]=at[j];
at[j]=t;
q=bt[i];
bt[i]=bt[j];
bt[j]=q;
strcpy(c[i],pname[i]);
strcpy(pname[i],pname[j]);
strcpy(pname[j],c[i]);
}
}
wt[0]=0;
for(i=0;i<n;i++)
{
wt[i+1]=wt[i]+bt[i];
sum=sum+(wt[i+1]-at[i]);
tt[i]=wt[i]+bt[i];
ss=ss+bt[i];
}
avgwt=(float) sum/n;
avgtt=(float) sbt/n;
printf("\n\nAverage waiting time=%f",avgwt);
printf("\n\nAverage turn-around time=%f",avgtt);
printf("\n\n GANTT CHART\n");
for(i=0;i<n;i++)
{printf("|\t%s\t",pname[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
printf("%d\t\t",wt[i]);
}
printf("%d\n",ss);
printf("\n");
}


Other 22 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

11/11/2007 2:47:46 AMdheeraj

thanks alot for providing these source codes
(If this comment was disrespectful, please report it.)

 
1/21/2008 5:15:04 AMriza

can u translate that in java program
(If this comment was disrespectful, please report it.)

 
11/1/2008 4:13:51 AMMangal Dev

Sir ,i have a doubt in ur code or may be i am not able to understand correctly..u have calclulated waiting time of a process by adding waiting time and burst time of previous process...what if arrival time is more than this and next process doesnt have to wait so this process must have 0 waiting time...e.g.consider proc1 having arrTime 0 bursttme 24 sec...proc2 having arrtime 30 sec burst time 10sec..proc3 having arrTime 100sec bursttime 12sec.....
(If this comment was disrespectful, please report it.)

 
8/17/2009 6:23:40 PMFassil

I think u forgot 2 #include library file nd it don't calculate Average waiting time correctly.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.