Coders Packet

Python Program to implement CPU Scheduling with FCFS or SJF

By Akhilan N

This is a python program to find the CPU scheduling using First Come First Serve or Shortest Job First

There are 3 files:

1 - cpuscheduling.py

2 - firstComeFirstServer.py

3 - sjf.py

cpuscheduling.py:-

   This is the main program.

   It imports the other 2 files - firstComeFirstServer.py and sjf.py

   Based on the user's choice the respective functions are called

firstComeFirstServer.py

   This module implements both versions(with arrival time and without arrival time) for FCFS.

   Based on the user's input witharrivaltime() or withoutarrivaltime() is called.

   The no. of process and their process's burst time and(if required) arrival time is received as input.

   For witharrivaltime() the processes are sorted based on their arrival time

   The solvescheduling() is used to find the schedule.

   If witharrivaltime() is used then the waiting time differs so the if condition is used to check it.

   total_executed_time is used to hold the sum of all the burst times of the processes which are executed so far.

   Then the output is printed.

sjf.py

   All the processes are assumed to arrive at time t = 0.

   The no. of process and their burst time are received as input. 

   Then the processes are sorted based on their burst time(increasing order).

   total_executed_time is used to hold the sum of all the burst times of the processes which are executed so far.

   Since all the processes arrive at t = 0 the waiting time is the same as the total executed time.

  Then the output is printed.

Download Complete Code

Comments

No comments yet