0% found this document useful (0 votes)
38 views9 pages

Flow Chart

The document describes a flow chart for simulating a FCFS queue scheduling algorithm. It involves: 1) Defining data structures like a queue and process attributes. 2) Populating the queue with arrival processes ordered by arrival time. 3) Simulating by dequeuing the next process, updating time, and executing bursts. 4) Recording waiting times and turnaround times for each process. 5) Repeating until the queue is empty and calculating average times.

Uploaded by

Kavi Sanjai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views9 pages

Flow Chart

The document describes a flow chart for simulating a FCFS queue scheduling algorithm. It involves: 1) Defining data structures like a queue and process attributes. 2) Populating the queue with arrival processes ordered by arrival time. 3) Simulating by dequeuing the next process, updating time, and executing bursts. 4) Recording waiting times and turnaround times for each process. 5) Repeating until the queue is empty and calculating average times.

Uploaded by

Kavi Sanjai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

FLOW CHART:

EXP NO:

DATE:

AIM:
To write a c program for application of queue in stimulation of FCFS.

OBJECTIVE:
By using this program, you can learn to analyse the turnaround time, waiting time, and
response time of processes in an FCFS system using a queue, helping you understand the
algorithm's efficiency and drawbacks.

ALGORITHM:
1. Start the program.

2. Define your data structures:

• Create a queue data structure to represent the ready queue of processes.

• Define a structure or class to represent a process, including attributes like process ID,

arrival time, burst time, etc.

• Initialize a timer or counter to keep track of the current time.

3. Create a list of processes:

• Populate the queue with processes, including their attributes (e.g., process ID, arrival
time, burst time).

• Make sure the processes are ordered based on their arrival times, as FCFS serves the
processes in the order they arrive.

4. Simulation loop:

• Enter a loop that continues until the queue is empty.

• Check if any new processes have arrived at the current time. If so, enqueue them in the ready
queue.

5. Service the next process:

• Dequeue the process at the front of the ready queue (the process with the earliest arrival
time).
• Update the timer with the current time.

• Execute the process for its burst time.

6. Record waiting times and turnaround times:

•Calculate and record the waiting time for each process (waiting time = turnaround time – burst
time).

• Keep track of these times for each process.

7. Continue the loop:

• Continue the simulation loop, repeating steps 3 to 5 until the queue is empty
8. Calculate average waiting and turnaround times:

• Calculate the average waiting time and average turnaround time for all processes.
9.Stop the program

PROGRAM:
#include<stdio.h>

int main()
{

int#include<stdio.h>
#include<string.h>
int main()
{
char pn[10][10],t[10];
int arr[10],bur[10],star[10],finish[10],tat[10],wt[10],i,j,n,temp;
int totwt=0,tottat=0;
printf("Enter the number of processes:");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("Enter the ProcessName, Arrival Time& Burst Time:");
scanf("%s%d%d",&pn[i],&arr[i],&bur[i]);
}
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
temp=bur[i];
bur[i]=bur[j];
bur[j]=temp;
strcpy(t,pn[i]);
strcpy(pn[i],pn[j]);
strcpy(pn[j],t);
}

}
}
for(i=0; i<n; i++)
{
if(i==0)
star[i]=arr[i];
else
star[i]=finish[i-1];
wt[i]=star[i]-arr[i];
finish[i]=star[i]+bur[i];
tat[i]=finish[i]-arr[i];
}
printf("\nPName Arrtime Burtime WaitTime Start TAT Finish");
for(i=0; i<n; i++)
{
printf("\n%s\t%3d\t%3d\t%3d\t%3d\t%6d\t%6d",pn[i],arr[i],bur[i],wt[i],star[i],tat[i],finish[i]);
totwt+=wt[i];
tottat+=tat[i];
}
printf("\nAverage Waiting time:%f",(float)totwt/n);
printf("\nAverage Turn Around Time:%f",(float)tottat/n);
return 0;
}

You might also like