Name: vartika jain
Registration no: 11024210020
Experiment no: 3B
Aim: Implement SJF in program with
arrival time 0 and discrete arrival time
for processes for non preemptive
scheduling.
Code:
n = int(input("Enter number of
processes: "))
process = []
for i in range(n):
at = int(input(f"Arrival Time of
P{i+1}:"))
bt = int(input(f"Burst Time of
P{i+1}:"))
[Link]([i+1, at, bt])
[Link](key=lambda x: x[1])
time = 0
completed = 0
ready = []
result = []
while completed < n:
for p in process:
if p not in ready and p not in result
and p[1] <= time:
[Link](p)
if ready:
[Link](key=lambda x: x[2])
cur = [Link](0)
1
Name: vartika jain
Registration no: 11024210020
pid, at, bt = cur
if ready:
[Link](key=lambda x: x[2])
cur = [Link](0)
pid, at, bt = cur
start = time
time += bt
ct = time
tat = ct - at
wt = tat - bt
[Link]([pid, at, bt, ct, tat,
wt])
completed += 1
else:
time += 1
print("\nPID\tAT\tBT\tCT\tTAT\tWT")
total_tat = 0
total_wt = 0
for r in result:
print(*r)
total_tat += r[4]
total_wt += r[5]
print("\nAverage TAT =", total_tat / n)
print("Average WT =", total_wt / n)
Algorithm: Non-Preemptive SJF
Step1:Start
2
Name: vartika jain
Registration no: 11024210020
Step2: Input number of processes
n.
Step3: For each process:input Arrival
Time (AT).
Input Burst Time (BT).
Step4: Sort all processes according to
Arrival Time.
Step5: Set:current time = 0
completed = 0
Step 6:Repeat until all processes are
completed:
1) Add all processes to ready queue
whose.
arrival time ≤ current time
2) If ready queue is empty
increase time by 1.
3) Else: select process with minimum
burst time.
4) Execute selected process
completely.
5) Calculate: Completion Time (CT) =
current time + BT
Turnaround Time (TAT) = CT − AT
Waiting Time (WT) = TAT − BT
6) Update current time = CT
7) Mark process as completed
Step7: Compute:
Average TAT
Average WT
Step8: Display result table
3
Name: vartika jain
Registration no: 11024210020
Output: