Question

In: Computer Science

In C, write a program that will simulate the operations of the following Round-Robin Interactive scheduling...

In C, write a program that will simulate the operations of the following Round-Robin Interactive scheduling algorithm.

It should implement threads for the algorithm plus the main thread using a linked list to represent the list of jobs available to run. Each node will represent a Job with the following information:

  • int ProcessID
  • int time
    • time needed to finish executing

The thread representing the scheduler algorithm should continue running until all jobs end. This is simulated using the time variable in each node; the program thread will iterate through the linked list jobs until the list is empty. In each iteration, you will subtract a quantum amount from each job to simulate the processing time executing on a CPU. If a node time variable is less than or equal to zero, this will simulate that a process has completed, and it is time to remove this job/node from the list.

Main thread:

  • Ask the user to specify a value to be used as the quantum.
    • request the user to input the number of jobs, and then proceed to fill the information in each job node; each data item will be stored in a separate node.
    • Start the RoundRobin Thread and wait till all jobs finish.

RoundRobin thread:

  • The thread will simulate the Round Robin algorithm.
    • Displays data in the list in the order they were inserted.
    • Each iteration of the algorithm, the thread should deduct the quantum amount from each job.
    • If a job time reaches zero, remove this job from the linked list and continue to iterate the list.
    • When there are no more jobs in the list, exit the thread.

Solutions

Expert Solution

#include <stdio.h>
struct process{
      char process_name;
      int arrival_time,arrival_time1, burst_time,burst_time1, ct, waiting_time, turnaround_time,current_time,responsefinish,response;
      int status;
      float mtat;
}process_queue[10];
void sort(int limit){
   int i,j;
   struct process time;
   for(i=0;i<limit-1;i++){
       for(j=i+1;j<limit;j++){
           if(process_queue[i].arrival_time > process_queue[j].arrival_time){
               time = process_queue[i];
               process_queue[i] = process_queue[j];
               process_queue[j] = time;
           }
       }
   }
}
int main(){
   int limit;
   int burst_time,i;
   char c;
   printf("\nEnter Total Number of Processes:\t");
    scanf("%d", &limit);
      for(i = 0, c = 'A'; i < limit; i++, c++)
      {
            process_queue[i].process_name = c;
            printf("\nEnter Details For Process[%C]:\n", process_queue[i].process_name);
            printf("Enter Arrival Time : ");
            scanf("%d",&process_queue[i].arrival_time);
            process_queue[i].arrival_time1 = process_queue[i].arrival_time;
            printf("Enter Burst Time:\t");
            process_queue[i].arrival_time1 = process_queue[i].arrival_time;
            scanf("%d", &process_queue[i].burst_time);
            process_queue[i].burst_time1 = process_queue[i].burst_time;
            process_queue[i].status = 0;
          
      }
      int quantum;
      printf("Enter a quantum number:");
      scanf("%d",&quantum);
      sort(limit);
      printf("\nProcess Name\tArrival Time\tBurst Time\tWaiting Time\tTurnaround_time\tresponse\tmtat\n");
      int wait_time = 0,turnaround_time = 0;
      int time;
      int t = 0;
      i = 0;
      int j = 0;
      int k=0,index = 0,switches = 0,context = 0;
      while(1){
                   int min = 1000,index = limit;
                   if(k == limit){
                       break;
                   }
                   for(j=0;j<limit;j++){
                       if((process_queue[j].status != 1) && (process_queue[j].arrival_time <= t) && (process_queue[j].arrival_time < min)){
                               min = process_queue[j].arrival_time;
                               index = j;
                           }
                   }
                   if(min == 1000){
                       t++;
                   }else{
                       if(index != context){
                           context = index;
                           switches++;
                       }
                       if(process_queue[index].responsefinish == 0){
                           process_queue[index].response = t - process_queue[index].arrival_time1;
                           process_queue[index].responsefinish = 1;
                       }
                       for(i=0; ((i<quantum) && (process_queue[index].burst_time != 0)); i++){
                               process_queue[index].current_time=t+1;
                               t = t+1;  
                               process_queue[index].burst_time--;
                       }
                       if(process_queue[index].burst_time == 0){
                           k++;
                           process_queue[index].turnaround_time = process_queue[index].current_time - process_queue[index].arrival_time1;
                           turnaround_time = turnaround_time + process_queue[index].turnaround_time;
                           process_queue[index].waiting_time = process_queue[index].turnaround_time - process_queue[index].burst_time1;
                           wait_time = wait_time + process_queue[index].waiting_time;  
                           process_queue[index].status = 1;
                           process_queue[index].mtat = (float)process_queue[index].turnaround_time/process_queue[index].burst_time1;
                           printf("\n%c\t\t%d\t\t%d\t\t%d\t\t%d\t\t%d\t\t%0.2f", process_queue[index].process_name, process_queue[index].arrival_time1, process_queue[index].burst_time1, process_queue[index].waiting_time,process_queue[index].turnaround_time,process_queue[index].response,process_queue[index].mtat);
                       }
                       else{
                           if(k != limit-1){
                               process_queue[index].arrival_time = t + 1;
                           }
                       }
               }
      }
      float average_waiting_time,average_turnaround_time;
      average_waiting_time = wait_time / limit;
      average_turnaround_time = turnaround_time / limit;
      printf("\n\nAverage waiting time:\t%f\n", average_waiting_time);
      printf("Average Turnaround Time:\t%f\n", average_turnaround_time);
      printf("context switches\t%d\n",switches);
   return 0;
}  

Output

Please upvote.please comment if queries.


Related Solutions

Round Robin Simulation Description: Write a program in c++ that utilizes STL queue (or your own...
Round Robin Simulation Description: Write a program in c++ that utilizes STL queue (or your own queue implementation) that simulates the round robin process scheduling algorithm. WITH COMMENTS Requirement: - write a class Process that holds following integer information: id, arrival_time, time_needed, finished_time. - read and initiate 5 Process objects from associated file (robin. txt) - file format: id, arrival_time, time_needed - once a process is finished, mark its finished_time accordingly. - CPU time frame: 4. - utilize a queue...
Compare First Come First Served Scheduling, and Round Robin Scheduling. In your comparison, include discussions of...
Compare First Come First Served Scheduling, and Round Robin Scheduling. In your comparison, include discussions of their potential advantages and disadvantages, and which scheduling scheme performs better under what job load conditions. (You need to give proper reasons.)
Write a C program with the following prompt *do not use gotostatement* "Write an interactive...
Write a C program with the following prompt *do not use goto statement* "Write an interactive program that implements a simple calculator. The program should allow the user to choose a binary arithmetic operation and enter two terms to which to apply the operation. The program should then compute the result and display it to the user. Your calculator will have two modes: double-precision mode and integer mode. Double-precision mode will do calculations and output using variables of type double....
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling...
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a quantum (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue. For example, we have the following queue with the quantum of 100ms. A(150) - B(80)...
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling...
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a quantum (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue. For example, we have the following queue with the quantum of 100ms. A(150) - B(80)...
Java round robin scheduling algorithm: 10 processes arrive at the same time and the time that...
Java round robin scheduling algorithm: 10 processes arrive at the same time and the time that each requires is random. Show that the output of the original list and list as it changes all the way until nothing is left in the array. Using only main method and not any additional static methods and Only using scanner, arrays, and for looper while/do while loops. No array lists or other methods in java.
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...
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
An operating system uses the Round Robin (RR) without priority CPU scheduling algorithm, with a quantum...
An operating system uses the Round Robin (RR) without priority CPU scheduling algorithm, with a quantum = 4. Consider the following set of processes in this OS, with the length of the CPU burst time given in milliseconds, and the shown priority. The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. Process Burst Time Priority P1 5 2 P2 10 5 P3 4 1 P4 6 4 P5 9 3...
Solve the the process scheduling problem using the round robin FCFS algorithm studied in assignment 7....
Solve the the process scheduling problem using the round robin FCFS algorithm studied in assignment 7. The program will show the order of execution of the processing and will provide the average waiting time for the following scenarios: a) Time quantum =1 b) Time Quantum=3 Use the table below to draw the Gantt Chart (Spread sheet or by hand). Process ID Arrival Time Burst Time 1 0 4 2 1 5 3 2 2 4 3 1 5 4 6...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT