Skip to content

Instantly share code, notes, and snippets.

@douglas-vaz
Created September 13, 2012 17:46
Show Gist options
  • Save douglas-vaz/3716144 to your computer and use it in GitHub Desktop.
Save douglas-vaz/3716144 to your computer and use it in GitHub Desktop.
First Come, Fist Serve Scheduling Algorithm Implementation
#!/usr/bin/python2
print 'Enter number of processes'
n, proc_queue, time = int(raw_input()), [], 0
for i in xrange(n):
proc = []
print 'Enter PID'
proc.append(raw_input())
print 'Enter arrival time'
proc.append(int(raw_input()))
print 'Enter execution time'
proc.append(int(raw_input()))
proc_queue.append(proc)
proc_queue.sort(key = lambda proc_queue:proc_queue[1])
for proc in proc_queue:
time = time if time > proc[1] else proc[1]
time = time + proc[2]
proc.append(time)
proc.append(proc[3] - proc[2] - proc[1] if time > proc[1] else 0)
print '\n'
print '{:<4} {:<12} {:<12} {:<12} {:<12}'.format(*'PID_Arrival Time_Burst Time_Waiting Time_Finish Time'.split('_'))
for proc in proc_queue:
print '{:<4} {:<12} {:<12} {:<12} {:<12}'.format(proc[0],proc[1],proc[2],proc[4],proc[3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment