Question

In: Computer Science

Hi Guys, The assignment in Process Scheduling Operating System to write C code that implement FCFS...

Hi Guys,

The assignment in Process Scheduling Operating System to write C code that implement FCFS & Round-Robin ( Without using any array) but we can use linkedlist

Solutions

Expert Solution

PROGRAM FOR FCFS(first come first serve)PROCESS SCHEDULING

#include <stdio.h>
#include <stdlib.h>
/*we know that fcfs is non preemptive scheduling algorithm that means we cannot preempt the process in middle
        the process will be executed till its end */
struct fcfs
{
   int at,ct,bt,tat,pid,wt;
};// making a structure
int main()
{
   int n,i,j;
   float awt,atat;
    struct fcfs allfcfs[100],temp; //decrearing a structure
    printf("enter how many processes u want to enter:");
    scanf("%d",&n);// entering no of processes you want to execute
    for(i=0;i<n;i++)
    {
       printf("enter the arrival time of %d process:",i+1);
       scanf("%d",&allfcfs[i].at);// enter arrival time of process i
       printf("enter the burst time of %d process:",i+1);
       scanf("%d",&allfcfs[i].bt);// enter burst time of process i
       allfcfs[i].pid=i+1;
   }// this loop is all about entering process details
   for(i=0;i<n;i++)
   {
       for(j=0;j<n-1;j++)
       {
           if(allfcfs[j].at>allfcfs[j+1].at)
           {
               temp=allfcfs[j];
               allfcfs[j]=allfcfs[j+1];
               allfcfs[j+1]=temp;
           }
       }
      
   }// this loop is all about sorting process based on their arrival time
   int c=0;
   for(i=0;i<n;i++)
   {
       if(i==0)
       {
            c=allfcfs[i].at;  
       }
       else
       {
           if(allfcfs[i].at>allfcfs[i-1].ct)
           {
               c=allfcfs[i].at-allfcfs[i-1].ct;
           }
           else
           {
               c=0;
           }
        }
        if(i>0)
       {
           allfcfs[i].ct=allfcfs[i-1].ct+allfcfs[i].bt+c;   calculating cpu time of process i
       }  
       else
       {  
           allfcfs[i].ct=allfcfs[i].bt+c;
       }
       allfcfs[i].tat=allfcfs[i].ct-allfcfs[i].at;// calculting turn around time of process i
       allfcfs[i].wt=allfcfs[i].ct-allfcfs[i].bt-allfcfs[i].at; calculating waiting time of process i  
       awt=awt+allfcfs[i].wt;// for calculating average waiting time we are finding the sum of waiting times of all processes
       atat=atat+allfcfs[i].tat;
   }
   printf("Average Turn Around Time is %f\n",(float)(atat/n));//printing average turn around time
    printf("Average Waiting time is %f",(float)(awt/n));// printing average waiting time
}

PROGRAM FOR RR(round robin) PROCESS SCHEDULING


#include<stdio.h>
struct RR{
    int pid,bt,bt1,ct,tat,wt,f;
};     // making a structure for rr


main()
{
   struct RR rr[100];declearing a structure
    int n,i,q,st=0,c=0;
    float atat=0,awt=0;
    printf("enter no of processes:");//entering how many processes you want to enter
    scanf("%d",&n);
    for (i=0;i<n;i++){
        rr[i].pid=i+1;
        rr[i].f=0;
        printf("enter the bt:");
        scanf("%d",&rr[i].bt);
        rr[i].bt1=rr[i].bt;
        printf("---------------------------\n");
    }   // entering the process details
  
    printf("enter time quantum:");
  
    scanf("%d",&q);// entering the time quantum(the amount time will be given to every process while execution)
  
    while (1)
   {
      
     for (i=0;i<n;i++)
   {
        if ((rr[i].bt<=q)&&(rr[i].f==0))/*checking whether the process is completed or not and also checking whether the             remaining burst time of process is less than quantum or not*/
       {
            st=st+rr[i].bt;//here we are changing the cpu time by executing that process i
            rr[i].bt=0;// we are changing the burst time to 0 because the process is completed
            rr[i].f=1;// changing flag value to 1 because process i is completed
            c++;   // I used this variable to check no of processes completed till now
            rr[i].ct=st;
            rr[i].tat=rr[i].ct;// changing turn around time
            atat=atat+rr[i].tat; // changing average turn around time
            rr[i].wt=rr[i].tat-rr[i].bt1;waiting time calculation
            awt=awt+rr[i].wt;// changing average waiting time
        }
        else if (rr[i].bt>q) // checking burst time is greater than quantum if true we simply add that quantum to cpu time
       {
            st=st+q;
            rr[i].bt=rr[i].bt-q; //we decrement quantum value from the burst time because processi is executed q amount of time
        }
     }
     if (c==n)
        break;// break if all processes are completly executed
    }
    // printing average turn around time and waiting time
    printf("average Turn Around Time is %f\n",(float)(atat/n));// printing average turn around time
    printf("average Waiting Time is %f",(float)(awt/n));// printing average waiting time
}


Related Solutions

List of six process scheduling algorithms (for operating systems): First-Come, First-Served (FCFS) Scheduling Shortest-Job-Next (SJN) Scheduling...
List of six process scheduling algorithms (for operating systems): First-Come, First-Served (FCFS) Scheduling Shortest-Job-Next (SJN) Scheduling Priority Scheduling Shortest Remaining Time Round Robin(RR) Scheduling Multiple-Level Queues Scheduling Compare and contrast the algorithms against one another here. You have at least six algorithms, so this should be an extensive part of the project, and all research based.
in C++ We are going to implement the following scheduling algorithms 1. First-Come First-Served (FCFS) 2....
in C++ We are going to implement the following scheduling algorithms 1. First-Come First-Served (FCFS) 2. Shortest Remaining Time First (SRTF) 3. Highest Response Ratio Next (HRRN) 4. Round Robin, with di_erent quantum values (RR) We are interested to compute the following metrics, for each experiment: _ The average turnaround time _ The total throughput (number of processes done per unit time) _ The CPU utilization _ The average number of processes in the ready queue The simulator needs to...
An operating system uses the First-Come, First-Served (FCFS) CPU scheduling algorithm. Consider the following set of...
An operating system uses the First-Come, First-Served (FCFS) CPU scheduling algorithm. Consider the following set of processes in this OS, with the length of the CPU burst time given in milliseconds, and the shown priority. A larger priority number implies a higher priority. There is no pre-emption. The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. Process Burst Time Priority P1 2 2 P2 1 5 P3 4 1 P4...
Implement the CPU scheduling algorithm FCFS non-preemptive in python. Have the program answer the table. Simulate...
Implement the CPU scheduling algorithm FCFS non-preemptive in python. Have the program answer the table. Simulate and evaluate with the set of eight processes below. Assumptions: All processes are activated at time 0 Assume that no process waits on I/O devices. After completing an I/O event, a process is transferred to the ready queue. Waiting time is accumulated while a process waits in the ready queue. Turnaround time is a total of (Waiting time) + (CPU burst time) + (I/O...
Hi guys, I'm working on an assignment for my Java II class and the narrative for...
Hi guys, I'm working on an assignment for my Java II class and the narrative for this week's program has me a bit lost. I've put the narrative of the assignment in the quotation marks below. " Included with this assignment is an encrypted text file. A simple Caesar cipher was used to encrypt the data. You are to create a program which will look at the frequency analysis of the letters (upper and lowercase) to help “crack” the code...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of the class is to get the data, store it into a file, perform some operations and display data. For the purpose mentioned above, you should write a template class Directory for storing the data empID(template), empFirstName(string), empLastName(string), empContactNumber(string) and empAddress(string) of each Employee in a file EmployeeDirectory.txt. 1. Write a function Add to write the above mentioned contact details of the employee into EmployeeDirectory.txt....
C++ Write the code to implement a complete binary heap using an array ( Not a...
C++ Write the code to implement a complete binary heap using an array ( Not a vector ). Code for Max heap. Implement: AddElement, GetMax, HeapSort, ShuffleUp, ShuffleDown, etc Set array size to 31 possible integers. Add 15 elements 1,3,27,22,18,4,11,26,42,19,6,2,15,16,13 Have a default constructor that initializes the array to zeros.. The data in the heap will be double datatype. PART 2 Convert to the program to a template, test with integers, double and char please provide screenshots thank you so...
write a verilog code to implement a digital system that has an odd counter that counts...
write a verilog code to implement a digital system that has an odd counter that counts from 1 to 11. Also, this system has an output Y that detects a specific number in the odd counter. Test your code when you detect the number 3, the output Y is 1, if the counter value is set to 3, otherwise 0.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT