Skip to content

Instantly share code, notes, and snippets.

@tanayseven
Created October 17, 2012 17:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tanayseven/3906897 to your computer and use it in GitHub Desktop.
Save tanayseven/3906897 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)
@manas911
Copy link

in 11 line i am facing a problem that it is not runnning in python please tell sir what a proble

@courage2
Copy link

the program isn't running at all it is saying missing parentheses in call to print line 11 i don't know whats the problem can you debug it !!!!please

@Raymkindo
Copy link

@manas911 and @courage You need to put Parentheses in print(' ')

@Aayush19
Copy link

this program is written in python 2.7 so if you want to run this program in python 3.x you have to put parenthesis "()" after each print and also rename raw_input to input as python 3.x does not support raw_input

@sahasourav17
Copy link

in 11 line i am facing a problem that it is not runnning in python please tell sir what a proble

this code is written in python2 .
and if I'm not wrong you are using python 3 . That's why it shows an error.

@gnanasreekar
Copy link

#!/usr/bin/env python
process_queue = []
total_wtime = 0
n = int(input('Enter the total no of processes: '))
for i in range(n):
process_queue.append([])#append a list object to the list
process_queue[i].append(input('Enter p_name: '))
process_queue[i].append(int(input('Enter p_arrival: ')))
total_wtime += process_queue[i][1]
process_queue[i].append(int(input('Enter p_bust: ')))
print ("")

process_queue.sort(key = lambda process_queue:process_queue[1])

print ("ProcessName\tArrivalTime\tBurstTime")
for i in range(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