FCFS Scheduling of processes with same arrival time


Also Read

  • FCFS Scheduling of processes with different arrival time
  • Preemptive and Non Preemptive Scheduling
  • CPU Scheduling in Operating Systems

  • Given n processes with their burst times, the task is to find average waiting time and average turn around time using FCFS scheduling algorithm.

    As the name suggests First Come and First Server is based on queue. The process that comes first will be executed first and then it will move to the next process. It is non-preemptive and average waiting time is optional.It also cannot utilize resources in parallel.

    Algorithm :

    1. Input the processes along with their burst time (bt).
    2. Find waiting time (wt) for all processes.
    3. As first process that comes need not to wait so time for process 1 will be 0 i.e. wt[0] = 0.
    4. Find waiting time for all other processes i.e. for process i -> wt[i] = bt[i-1] + wt[i-1] .
    5. Find turnaround time = waiting_time + burst_time for all processes.
    6. Find average waiting time = total_waiting_time / no_of_processes.
    7. Similarly, find average turnaround time = total_turn_around_time / no_of_processes.

    Code - Python:
        # Function to find the waiting
        # time for all processes
        def findWaitingTime(processes, n, bt, wt):
            # waiting time for
            # first process is 0
            wt[0] = 0
        
            # calculating waiting time
            for i in range(1, n):
                wt[i] = bt[i - 1] + wt[i - 1]
        
        
        # Function to calculate turn
        # around time
        def findTurnAroundTime(processes, n, bt, wt, tat):
            # calculating turnaround
            # time by adding bt[i] + wt[i]
            for i in range(n):
                tat[i] = bt[i] + wt[i]
        
        
        # Function to calculate
        # average time
        def findavgTime(processes, n, bt):
            wt = [0] * n
            tat = [0] * n
            total_wt = 0
            total_tat = 0
        
            # Function to find waiting
            # time of all processes
            findWaitingTime(processes, n, bt, wt)
        
            # Function to find turn around
            # time for all processes
            findTurnAroundTime(processes, n, bt, wt, tat)
        
            # Display processes along
            # with all details
            print("Processes Burst time " +
                  " Waiting time " +
                  " Turn around time")
        
            # Calculate total waiting time
            # and total turn around time
            for i in range(n):
                total_wt = total_wt + wt[i]
                total_tat = total_tat + tat[i]
                print(" " + str(i + 1) + "\t\t" + str(bt[i]) + "\t " + str(wt[i]) + "\t\t " + str(tat[i]))
        
            print("Average waiting time = " + str(total_wt / n))
            print("Average turn around time = " + str(total_tat / n))
        
        
        if __name__ == "__main__":
            # process id's
            processes = [1, 2, 3]
            n = len(processes)
        
            # Burst time of all processes
            burst_time = [10, 5, 8]
        
            findavgTime(processes, n, burst_time)