Question

DUE ASAP ! Program Assignment: 1. Implement the following 3 scheduling Algorithms: a. First Come, First...

DUE ASAP !

Program Assignment: 1. Implement the following 3 scheduling Algorithms: a. First Come, First Served (batch, non preemptive) (FCFS) b. Shortest Job First (batch, non preemptive) (SJF) c. Round Robin (preemptive) (RR) 2. Implement Using C or C++ on a Linux machine 3. To run the 3 scheduling algorithms, create a Priority Scheduling Program with menu options that will call the 3 scheduling programs, (fcfs, sjf, and Round Robin). These are simulation algorithms, that will be run from your terminal window. 4. Below is an example of an input file. This is the input that generated the example output. ProcessID Arrival cpuBurst Priority 100 0 10 1 101 6 10 1 102 8 4 1 103 12 20 1 104 19 15 1 105 30 5 1 106 35 10 1 4.Below is an example of the way the output should look. In this example each algorithm is run with the same data file (“jobs.txt”), then the output and statistics are presented. This is a good example to use to test your algorithms and program. For the Round Robin, the time Quanta was 15, I think. ProcessID Arrival cpuBurst Priority 100 0 10 1 101 6 10 1 102 8 4 1 103 12 20 1 104 19 15 1 105 30 5 1 106 35 10 1 number of jobs in newQ = 7 Terminated Jobs (First Come, First Served) ProcessId arrival completion 100 0 10 101 6 20 102 8 24 103 12 44 104 19 59 105 30 64 106 35 74 Run Stats Throughput = 0.09 Average turnaround time = 26.43 Average response time = 15.86 ProcessID Arrival cpuBurst Priority 100 0 10 1 101 6 10 1 102 8 4 1 103 12 20 1 104 19 15 1 105 30 5 1 106 35 10 1 Number of jobs in newQ = 7 Terminated Jobs. (Shortest Job First) ProcessId arrival completion 100 0 10 102 8 14 101 6 24 104 19 39 105 30 44 106 35 54 103 12 74 Run Stats Throughput = 0.09 Average turnaround time = 21.29 Average response time = 10.71 ProcessID Arrival cpuBurst Priority 100 0 10 1 101 6 10 1 102 8 4 1 103 12 20 1 104 19 15 1 105 30 5 1 106 35 10 1 Number of jobs in newQ = 7 Terminated Jobs. (Round Robin) ProcessId arrival completion 100 0 10 101 6 20 102 8 24 104 19 54 103 12 59 105 30 64 106 35 74 Run Stats Throughput = 0.09 Average turnaround time = 27.86 Average response time = 11.14 5. Below is an example of a routine used to output the run statistics: void showRunStats(int numJobs, int time) { int j; float tPut, turn, resp; /* Initialize variables. */ turn = 0.0f; resp = 0.0f; /* Calculate turnaround time and waiting time. In this calculation the waiting time is really should be called response time. */ for(j=0;j

Homework Answers

Answer #1

FCFS:

#include<stdio.h>
int main(){
int bt[10]={0},at[10]={0},tat[10]={0},wt[10]={0},ct[10]={0};
int n,sum=0;
float totalTAT=0,totalWT=0;
printf("\n");
printf("First Come First Serve Scheduling\n");
printf("\n");
printf("Enter number of processes ");
scanf("%d",&n);
for(int i=0;i<n;i++){
    printf("Arrival time of process[%d]    ",i+1);
    scanf("%d",&at[i]);
    printf("Burst time of process[%d] ",i+1);
    scanf("%d",&bt[i]);
    printf("\n\n");
}
//calculate completion time of processes
for(int j=0;j<n;j++)
{
sum+=bt[j];
ct[j]+=sum;
}
//calculate turnaround time and waiting times
for(int k=0;k<n;k++)
{
tat[k]=ct[k]-at[k];
totalTAT+=tat[k];
}
for(int k=0;k<n;k++)
{
wt[k]=tat[k]-bt[k];
totalWT+=wt[k];
}
printf("Solution: \n\n");
printf("P#\t AT\t BT\t CT\t TAT\t WT\t\n\n");
for(int i=0;i<n;i++)
{
printf("P%d\t %d\t %d\t %d\t %d\t %d\n",i+1,at[i],bt[i],ct[i],tat[i],wt[i]);
}
printf("\n\nAverage Turnaround Time = %f\n",totalTAT/n); printf("Average WT = %f\n\n",totalWT/n);
return 0;
 }

Priority:

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

int et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[10];

int totwt=0,totta=0;

float awt,ata;

char pn[10][10],t[10];

//clrscr();

printf("\t\t\t\t\t_________________________________________________________

__________\n\n");

printf("\t\t\t\t\t\t\tPriority Scheduling\n");

printf("\t\t\t\t\t______________________________________________________

_____________\n\n\n");

printf("Enter the number of process:");

scanf("%d",&n);

for(i=0; i<n; i++)

{

printf("Enter process name:");

scanf("%s",pn[i]);

printf("Enter Arrival Time:");

scanf("%d",&at[i]);

printf("Enter Execution Time:");

scanf("%d",&et[i]);

printf("Enter Priority:");

scanf("%d",&p[i]);

printf("\n");

}

for(i=0; i<n; i++)

for(j=0; j<n; j++)

{

if(p[i]<p[j])

{

temp=p[i];

p[i]=p[j];

p[j]=temp;

temp=at[i];

at[i]=at[j];

at[j]=temp;

temp=et[i];

et[i]=et[j];

et[j]=temp;

11strcpy(t,pn[i]);

strcpy(pn[i],pn[j]);

strcpy(pn[j],t);

}

}

for(i=0; i<n; i++)

{

if(i==0)

{

st[i]=at[i];

wt[i]=st[i]-at[i];

ft[i]=st[i]+et[i];

ta[i]=ft[i]-at[i];

}

else

{

st[i]=ft[i-1];

wt[i]=st[i]-at[i];

ft[i]=st[i]+et[i];

ta[i]=ft[i]-at[i];

}

totwt+=wt[i];

totta+=ta[i];

}

awt=(float)totwt/n;

ata=(float)totta/n;

printf("\nPname\tarrivaltime\texecutiontime\tpriority\twaitingtime\ttatime");

for(i=0; i<n; i++)

printf("\n%s\t%5d\t\t%5d\t\t%5d\t\t%5d\t\t%5d",pn[i],at[i],et[i],p[i],wt[i],ta[i]);

printf("\nAverage waiting time is:%f",awt);

printf("\nAverage turnaroundtime is:%f",ata);

getch();

}

Round Robin

#include<stdio.h> 
int main() 
{
    int count,j,n,time,remain,flag=0,time_quantum;
    int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10]; 
   
    printf("\t\tRound Robin Scheduling\n\n"); 
   
    printf("Enter Total Process:\t "); 
    scanf("%d",&n); 
    remain=n;
    printf("\n"); 
    for(count=0;count<n;count++)
    {
        printf("Enter Arrival Time Process P[%d] :",count+1);
    scanf("%d",&at[count]); 
    printf("Enter Burst Time for Process P[%d]:",count+1); 
    scanf("%d",&bt[count]); rt[count]=bt[count];
    printf("\n"); }printf("Enter Time Quantum:\t"); 
    scanf("%d",&time_quantum);
    printf("\n\nProcess\t\tTurnaround Time\t\tWaiting Time\n\n"); 
    for(time=0,count=0;remain!=0;) { if(rt[count]<=time_quantum && rt[count]>0)
    {
        time+=rt[count]; 
        rt[count]=0; 
        flag=1;
        }
        else if(rt[count]>0)
        {
            rt[count]-=time_quantum;
            time+=time_quantum; 
            
        } 
        if(rt[count]==0 && flag==1)
        {
            remain--; 
            printf("P[%d]\t\t\t%d\t\t\t%d\n",count+1,time-at[count],time-at[count]-bt[count]); 
            wait_time+=time-at[count]-bt[count];
            turnaround_time+=time-at[count];
            flag=0; 
            
        }
        if(count==n-1) 
        count=0; 
        else if(at[count+1]<=time)
        count++; 
        else count=0;
    }
    printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n);
    printf("Avg Turnaround Time = %f",turnaround_time*1.0/n); 
    return 0;
}

SJF(Non- Preemptive):


#include<stdio.h>

int main()

{

int i,n,p[10]={1,2,3,4,5,6,7,8,9,10},min,k=1,btime=0;

int bt[10],temp,j,at[10],wt[10],tt[10],ta=0,sum=0; float wavg=0,tavg=0,tsum=0,wsum=0;

printf("\t\n");

printf("\tShortest Job First Non-Preemptive Scheduling\n");

printf("\\n");

printf("\nEnter the No. of processes :");

scanf("%d",&n);

for(i=0;i<n;i++)

{

printf("\tEnter the burst time of %d process :",i+1);

scanf(" %d",&bt[i]);

printf("\tEnter the arrival time of %d process :",i+1);

scanf(" %d",&at[i]);

printf("\n");

}

/*Sorting According to Arrival Time*/

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

if(at[i]<at[j])

{

temp=p[j];

p[j]=p[i];

p[i]=temp;

temp=at[j];

at[j]=at[i];

at[i]=temp;

temp=bt[j];

bt[j]=bt[i];

bt[i]=temp;

}}}

/*Arranging the table according to Burst time, Execution time and Arrival Time

Arrival time <= Execution time

*/

for(j=0;j<n;j++)

{

btime=btime+bt[j];

min=bt[k];

for(i=k;i<n;i++)

{

if (btime>=at[i] && bt[i]<min)

{

temp=p[k];

p[k]=p[i];

p[i]=temp;

temp=at[k];

at[k]=at[i];

at[i]=temp;

temp=bt[k];

bt[k]=bt[i];

bt[i]=temp;

}} k++;

}

wt[0]=0;

for(i=1;i<n;i++)

{

sum=sum+bt[i-1];

wt[i]=sum-at[i];

wsum=wsum+wt[i];

}

wavg=(wsum/n);

for(i=0;i<n;i++)

{

ta=ta+bt[i];

tt[i]=ta-at[i];

tsum=tsum+tt[i];

}

tavg=(tsum/n);

printf("\nProcess\t Burst\t Arrival\t Waiting\t Turn-around" );

for(i=0;i<n;i++)

{

printf("\n p%d\t %d\t %d\t\t %d\t\t\t%d",p[i],bt[i],at[i],wt[i],tt[i]);

}

printf("\n\nAVERAGE WAITING TIME : %f",wavg);

printf("\nAVERAGE TURN AROUND TIME : %f",tavg);

return 0;

}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
: Process Burst Arrival-time Priority A 2 1 3 B 8 0 2 C 3 1...
: Process Burst Arrival-time Priority A 2 1 3 B 8 0 2 C 3 1 2 D 12 2 1 Note: A lower priority number indicates a higher priority For each of the following CPU scheduling algorithms, determine the turnaround and wait times for each process as well as the average wait and turnaround times. Show all your working. First Come First Serve Preemptive Priority Scheduling
Process Burst Arrival-time Priority A 2 1 3 B 8 0 2 C 3 1 2...
Process Burst Arrival-time Priority A 2 1 3 B 8 0 2 C 3 1 2 D 12 2 1 Note: A lower priority number indicates a higher priority. (Show all your working) For each of the following CPU scheduling algorithms, determine the turnaround and wait times for each process as well as the average wait and turnaround times. First Come First Serve Preemptive Priority Scheduling
The following processes are being scheduled using a preemptive, round-robin scheduling algorithm. (20 Marks) Process    ...
The following processes are being scheduled using a preemptive, round-robin scheduling algorithm. Process     Priority Burst Time Arrival P1 40 20 0 P2 30 25 25 P3 30 15 30 P4 35 10 60 P5 5 10 100 P6 10 10 105 Each process is assigned a numerical priority, with a higher number indicating a higher relative priority. In addition to the processes listed below, the system also has an idle task (which consumes no CPU resources and is identified...
Process Burst Arrival-time Priority A 2 1 3 B 8 0 2 C 3 1 2...
Process Burst Arrival-time Priority A 2 1 3 B 8 0 2 C 3 1 2 D 12 2 1 Note: A lower priority number indicates a higher priority For each of the following CPU scheduling algorithms, determine the turnaround and wait times for each process as well as the average wait and turnaround times. 2. Round Robin with quantum=2 ms (assume 1ms = 1 CPU Burst) Continuation of https://www.chegg.com/homework-help/questions-and-answers/refer-information-provided-process-burst-arrival-priority-time-2-1-3-b-8-0-2-3-1-2-d-12-2--q58716840
The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm. Each process is...
The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm. Each process is assigned a numerical priority,with a higher number indicating a higher relative priority. The scheduler will execute the highest-priority process. For processes with the same priority, a round-robin scheduler will be used with a time quantum of 10 units. If a process is preempted by a higher-priority process, the preempted process is placed at the end of the queue. Process            Burst Time Arrival Time...
The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm. Process Priority Burst...
The following processes are being scheduled using a preemptive, priority-based, round-robin scheduling algorithm. Process Priority Burst Arrival P 1 8 15 0 P 2 3 20 0 P 3 4 20 20 P 4 4 20 25 P 5 5 545 P 6 5 15 55 Each process is assigned a numerical priority, with a higher number indicating a higher relative priority. The scheduler will execute the highestpriority process. For processes with the same priority, a round-robin scheduler will be...
Problem 6 The following tables show the timing for processes using two different scheduling algorithms based...
Problem 6 The following tables show the timing for processes using two different scheduling algorithms based on the table of process arrival times and burst times (All ties were resolved using the arrival time). Using this information: Calculate the average turnaround time for each algorithm. Show your work. Name the scheduling algorithm used to generate the timing tables. Process Arrival Time Burst Time P1 0 4 P2 3.9 1 P3 2.9 3 P4 0.9 2 P5 1.9 4 Mystery Algorithm...
Write a program that does the following and prints out the result          Use a do-while...
Write a program that does the following and prints out the result          Use a do-while loop and switch statement          Enter value x and a case number n          for n = 0 exit else continue          n=100 result = x * 9          n=102 result = x + 10 and continue          n=103 result = (x + 10) * x          n=104 and 106 result = x / x default    result = 99; test with x =...
Consider the following set of jobs to be scheduled for execution on a single CPU system....
Consider the following set of jobs to be scheduled for execution on a single CPU system. Job Arrival Time Burst (msec) Priority A 0 6 3 (Silver) B 1 2 1 (Diamond) C 3 5 3 (Silver) D 5 3 4 (Bronze) E 7 2 2 (Gold)    (a)     Draw a Gantt chart showing First-Come-First-Served (FCFS) scheduling for these jobs. [3 Marks] Answer (a) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16...
SQL A manufacturing company’s data warehouse contains the following tables. Region region_id (p) region_name super_region_id (f)...
SQL A manufacturing company’s data warehouse contains the following tables. Region region_id (p) region_name super_region_id (f) 101 North America 102 USA 101 103 Canada 101 104 USA-Northeast 102 105 USA-Southeast 102 106 USA-West 102 107 Mexico 101 Note: (p) = "primary key" and (f) = "foreign key". They are not part of the column names. Product product_id (p) product_name 1256 Gear - Large 4437 Gear - Small 5567 Crankshaft 7684 Sprocket Sales_Totals product_id (p)(f) region_id (p)(f) year (p) month (p)...