1
+ class process :
2
+ def __init__ (self ,process_id ,arrival_time ,burst_time ,priority ,q ,ready ):
3
+ self .process_id = process_id
4
+ self .arrival_time = arrival_time
5
+ self .burst_time = burst_time
6
+ self .priority = priority
7
+ self .ready = ready
8
+ self .q = q
9
+
10
+
11
+ def Queue (t1 ):
12
+ t1 = int (t1 )
13
+ if (t1 == 0 or t1 == 1 or t1 == 2 or t1 == 3 ):
14
+ return 1
15
+ else :
16
+ return 2
17
+
18
+
19
+ limit = int (input ("Enter Total Number of Processes:" ))
20
+
21
+ Process = []
22
+ for i in range (limit ):
23
+ pid = int (input ("Process ID:" ))
24
+ time = int (input ("Arrival Time:" ))
25
+ btime = int (input ("Burst Time:" ))
26
+ priority = int (input ("Process Priority:" ))
27
+ q = Queue (priority )
28
+ ready = 0
29
+ Process_1 = process (process_id = pid ,arrival_time = time ,burst_time = btime ,priority = priority ,q = q ,ready = ready )
30
+ Process .append (Process_1 )
31
+
32
+ time = Process [0 ].burst_time
33
+ for i in range (limit ):
34
+ for count in range (limit ):
35
+ if Process [count ].arrival_time < time :
36
+ Process [count ].ready = 1
37
+ for count in range (i ,limit - 1 ):
38
+ for j in range (count + 1 ,limit ):
39
+ if Process [count ].ready == 1 and Process [j ].ready == 1 :
40
+ if Process [count ].q == 2 and Process [j ].q == 1 :
41
+ temp = Process [count ]
42
+ Process [count ]= Process [j ]
43
+ Process [j ]= temp
44
+ for count in range (i ,limit - 1 ):
45
+ for j in range (count + 1 ,limit ):
46
+ if Process [count ].ready == 1 and Process [j ].ready == 1 :
47
+ if Process [count ].q == 1 and Process [j ].q == 1 :
48
+ if Process [count ].burst_time > Process [j ].burst_time :
49
+ temp = Process [count ]
50
+ Process [count ]= Process [j ]
51
+ Process [j ]= temp
52
+ else :
53
+ break
54
+
55
+ print ("\n Process[%d]:\t Time:\t %d To %d\n " % (Process [i ].process_id , time , time + Process [i ].burst_time ))
56
+ time = time + Process [i ].burst_time
57
+ for count in range (i ,limit ):
58
+ if Process [count ].ready == 1 :
59
+ Process [count ].ready = 0
0 commit comments