Skip to content

Instantly share code, notes, and snippets.

@yangzhou95
Forked from tanayseven/FCFS.py
Created September 11, 2017 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangzhou95/6d281c0f3b6443190ccd5114194a70a1 to your computer and use it in GitHub Desktop.
Save yangzhou95/6d281c0f3b6443190ccd5114194a70a1 to your computer and use it in GitHub Desktop.
FCFS (First Come First Serve) Process scheduling using python
#!/usr/bin/env python
process_queue = []
total_wtime = 0
n = int(raw_input('Enter the total no of processes: '))
for i in xrange(n):
process_queue.append([])#append a list object to the list
process_queue[i].append(raw_input('Enter p_name: '))
process_queue[i].append(int(raw_input('Enter p_arrival: ')))
total_wtime += process_queue[i][1]
process_queue[i].append(int(raw_input('Enter p_bust: ')))
print ''
process_queue.sort(key = lambda process_queue:process_queue[1])
print 'ProcessName\tArrivalTime\tBurstTime'
for i in xrange(n):
print process_queue[i][0],'\t\t',process_queue[i][1],'\t\t',process_queue[i][2]
print 'Total waiting time: ',total_wtime
print 'Average waiting time: ',(total_wtime/n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment