Skip to content

Commit 7f6f39c

Browse files
fcfsmultiprocessing.py
Creating processes using multi programming in python which can scheduled in shortest job first manner.
1 parent 5792261 commit 7f6f39c

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import multiprocessing
2+
import os
3+
import time
4+
5+
def proc(n):
6+
time.sleep(n)
7+
8+
#creating processes
9+
p0=multiprocessing.Process(target=proc,args=(2,))
10+
p1=multiprocessing.Process(target=proc,args=(3,))
11+
p2=multiprocessing.Process(target=proc,args=(6,))
12+
p3=multiprocessing.Process(target=proc,args=(21,))
13+
14+
#Burst time for process
15+
bursttime=[21,3,6,2]
16+
17+
#sorting just to compute sortest job first
18+
burst.sort()
19+
20+
#storing intial time for all process with n+1 size
21+
t=[0,0,0,0,0]
22+
23+
#intializing waiting time array of size n
24+
wt=[0]*4
25+
26+
#intializing turn around time array
27+
tt=[0]*4
28+
29+
#taking time at the beggining at t[0] rest of
30+
#all we take after a process end and t[j]-t[i]
31+
#will compute the time taken to complete the process
32+
t[0]=time.time()
33+
34+
#strating process p0
35+
p0.start()
36+
p0.join()
37+
38+
#taking time after process p0
39+
t[1]=time.time()
40+
41+
#strating process p1
42+
p1.start()
43+
p1.join()
44+
45+
#taking time after process p1
46+
t[2]=time.time()
47+
48+
#strating process p2
49+
p2.start()
50+
p2.join()
51+
52+
#taking time after process p2
53+
t[3]=time.time()
54+
55+
#strating process p3
56+
p3.start()
57+
p3.join()
58+
59+
#taking time after process p3
60+
t[4]=time.time()
61+
62+
i=0
63+
while i<=4:
64+
tt[i]=t[i+1]-t[i]
65+
wt[i]=tt[i]-bursttime[i]
66+
i+=1
67+
printf("Average waiting time:",sum(wt)/len(wt))
68+
69+
printf("Average turn around time:",sum(tt)/len(tt))

0 commit comments

Comments
 (0)