Question

Implement a program for SJF(non-preemptive) scheduling. Given n processes with their burst times and Arrival Time,...

Implement a program for SJF(non-preemptive) scheduling. Given n processes with their burst times and Arrival Time, the task is to find average waiting time and average turn around time and completion time using SJF scheduling algorithm. Language in C

• Completion Time: Time at which process completes its execution.

• Turn Around Time: Time Difference between completion time and arrival time. Turn Around Time = Completion Time – Arrival Time

• Waiting Time: Time Difference between turn around time and burst time. Waiting Time = Turn Around Time – Burst Time

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is a program for the implementation of SJF (Non-preemptive) scheduling.
#include<iostream>
using namespace std;
int mat[10][6];

void swap(int *a, int *b)
{
   int temp = *a;
   *a = *b;
   *b = temp;
}

void arrangeArrival(int num, int mat[][6])
{
   for(int i=0; i<num; i++)
   {
       for(int j=0; j<num-i-1; j++)
       {
           if(mat[j][1] > mat[j+1][1])
           {
               for(int k=0; k<5; k++)
               {
                   swap(mat[j][k], mat[j+1][k]);
               }
           }
       }
   }
}

void completionTime(int num, int mat[][6])
{
   int temp, val;
   mat[0][3] = mat[0][1] + mat[0][2];
   mat[0][5] = mat[0][3] - mat[0][1];
   mat[0][4] = mat[0][5] - mat[0][2];
  
   for(int i=1; i<num; i++)
   {
       temp = mat[i-1][3];
       int low = mat[i][2];
       for(int j=i; j<num; j++)
       {
           if(temp >= mat[j][1] && low >= mat[j][2])
           {
               low = mat[j][2];
               val = j;
           }
       }
       mat[val][3] = temp + mat[val][2];
       mat[val][5] = mat[val][3] - mat[val][1];
       mat[val][4] = mat[val][5] - mat[val][2];
       for(int k=0; k<6; k++)
       {
           swap(mat[val][k], mat[i][k]);
       }
   }
}

int main()
{
   int num, temp;
  
   cout<<"Enter number of Process: ";
   cin>>num;
  
   cout<<"...Enter the process ID...\n";
   for(int i=0; i<num; i++)
   {
       cout<<"...Process "<<i+1<<"...\n";
       cout<<"Enter Process Id: ";
       cin>>mat[i][0];
       cout<<"Enter Arrival Time: ";
       cin>>mat[i][1];
       cout<<"Enter Burst Time: ";
       cin>>mat[i][2];
   }
  
   cout<<"Before Arrange...\n";
   cout<<"Process ID\tArrival Time\tBurst Time\n";
   for(int i=0; i<num; i++)
   {
       cout<<mat[i][0]<<"\t\t"<<mat[i][1]<<"\t\t"<<mat[i][2]<<"\n";
   }
  
   arrangeArrival(num, mat);
   completionTime(num, mat);
   cout<<"Final Result...\n";
   cout<<"Process ID\tArrival Time\tBurst Time\tWaiting Time\tTurnaround Time\n";
   for(int i=0; i<num; i++)
   {
       cout<<mat[i][0]<<"\t\t"<<mat[i][1]<<"\t\t"<<mat[i][2]<<"\t\t"<<mat[i][4]<<"\t\t"<<mat[i][5]<<"\n";
   }
}

Add a comment
Know the answer?
Add Answer to:
Implement a program for SJF(non-preemptive) scheduling. Given n processes with their burst times and Arrival Time,...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider 5 processes whose Arrival time and CPU Burst time is as follows (Process no: Arrival...

    Consider 5 processes whose Arrival time and CPU Burst time is as follows (Process no: Arrival time: Burst time): P1:0,6 P2:2,4 P3:3,2 P4: 5,5 P5: 6,9 Assume that the processes are scheduled using SJF (Non-preemptive) scheduling algorithm. The average waiting and turaround time is O 5.45, 11.60 O 5.40, 10.60 O 6.50, 10.99 O 5.45, 11.60

  • Answer the following using the processes and their corresponding arrival time and burst time. These processes...

    Answer the following using the processes and their corresponding arrival time and burst time. These processes are being scheduled using a preemptive, round-robin scheduling algorithm with a time quantum of 2 units. PID Arrival Time Burst Time P1 0 4 P2 1 5 P3 2 3 P4 3 2 P5 4 6 1. Use a Gantt chart to represent the above processes (5 points) 2. Calculate the average waiting time for each process (5 points) 3. Calculate the completion time...

  • Create a non-preemptive Priority process scheduler in java that considers the arrival time, burst time, and...

    Create a non-preemptive Priority process scheduler in java that considers the arrival time, burst time, and priority (1 being highest priority). Output the waiting time, turn around time, average waiting time, and average turn around time.

  • Consider the following set of processes, with the length of CPU burst in milliseconds.

    Consider the following set of processes, with the length of CPU burst in milliseconds. Process PI P2 P3 P4 P5 Arrival time 00 02 03 06 30 Burst time 10 12 14 16 05 Draw a Gantt chart that illustrates the execution of these processes using the preemptive shorte st job first (SJF) algorithm. Hence find the average waiting time. Draw a Gantt chart that illustrate the execution of these processes using preemptive priority scheduling algorithm. Given priority of each...

  • 8. Consider the following 5 processes in the ready queue: Process Burst Priority Arrival time n...

    8. Consider the following 5 processes in the ready queue: Process Burst Priority Arrival time n w P1 P2 w N P3 P P - W WE O P4 N P5 N A O Draw Gantt charts illustrating the execution of these processes for each of the following algorithms: (a) preemptive SJF, (b) RR (with quantum = 1), (C) FCFS, and (d) preemptive priority, and calculate the respective turnaround and waiting times.

  • Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:

    Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:Processburst TimePriorityP1103P211P323P414P552For each of the scheduling algorithms, FCFS, Shortest-Job-First (SJF, non-preemptive), Priority (smaller priority number implies higher scheduling priority), and RR (quantum = 1) do the following.Draw a Gantt chart to show how these processes would be scheduled.Give the turnaround time (total time from the first arrival into ready state until CPU-burst is completed) of each process.Give the waiting time (total time spent in the Ready state) of each process.Give...

  • Given the following set of processes with corresponding execution times (in ms), arrival times and priority...

    Given the following set of processes with corresponding execution times (in ms), arrival times and priority (1 – highest).  For each scheduling algorithm: Construct a table showing which process is active and for how long until all processes are completely serviced (as done in class). Calculate the average waiting time and turnaround time. Process ID Burst (ms) Arrival time P1 9 0 P2 12 0 P3 3 0 P4 30 0 P5 20 0 P6 10 0 First Come First Serve...

  • C language show all work 1. [50 pts] Given the following set of processes, with arrival...

    C language show all work 1. [50 pts] Given the following set of processes, with arrival times, priorities, and the length of the CPU burst in ms: Priority Arrival Time Burst time Process P1 P2 P3 P4 4. 3 2 0 0 10 (Note: lower number means higher priority, processes P1, P2, P3, and P4 arrive at the same time, in the given order). a. Draw a Gantt chart showing a FCFS scheduling algorithm. b. Draw a Gantt chart showing...

  • Cpu scheduling

    Consider the following set of processes, with the length of the CPU burst times given in milliseconds:a. Draw four Gantt charts illustrating the execution of the processes using FCFS, Preemptive SJF, a non-preemptive priority, and a RR (quantum=2) scheduling. (30 pts)Note: for the RR consider that the arriving time is 0 for all processesb. What is the average waiting time of each process for of the above scheduling algorithms? (10 pts)P1 8 2 0 P2 5 36P3 1 1 8...

  • OS CPU Scheduling 1. Given the following processes Process Arrival Time 0 Priority 5 P1 P2...

    OS CPU Scheduling 1. Given the following processes Process Arrival Time 0 Priority 5 P1 P2 P3 P4 Burst Time 10 5 8 15 2 2 3 2 a) Please demonstrate the SJF and LJF algorithms on the above. (Note: if they mention SJF or any other, make sure u do both the non- preemptive and preemptive) b) What are the differences between them?

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT