Advertisement
shawonrog2

SJF NON-PREMETIVE

Dec 8th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.01 KB | None | 0 0
  1. echo "Enter number of Process:"
  2. read n;
  3.  
  4. echo "Enter Burst Time :"
  5. read b;
  6.  
  7. for (( i = 0; i < n; i++ )); do
  8.     echo "P$(($i+1)):"
  9.     read bt[$i]
  10.     p[$i]=$(($i+1))
  11. done
  12.  
  13. # Sorting of burst time:
  14. for (( i = 0; i < n; i++ )); do
  15.   pos=$i
  16.   for (( j = i+1; j < n; j++ )); do
  17.     if [[ bt[$j] -lt bt[$pos] ]]; then
  18.       pos=$j
  19.     fi
  20.   done
  21.   temp=$((bt[$i]))
  22.   bt[$i]=$((bt[$pos]))
  23.   bt[$pos]=$temp
  24.  
  25.   temp=$((p[$i]))
  26.   p[$i]=$((p[$pos]))
  27.   p[$pos]=$temp
  28. done
  29.  
  30. wt[0]=0
  31.  
  32. for (( i = 1; i < n; i++ )); do
  33.  
  34.   wt[$i]=0
  35.   for (( j = 0; j < i; j++ )); do
  36.  
  37.     wt[$i]=$((wt[$i]+bt[$j]))
  38.    
  39.   done
  40.   total=$(($total+wt[$i]))
  41.  
  42. done
  43.  
  44. avg_wt=$(($total/$n))
  45. total=0
  46.  
  47. echo -e "Processt\tBurst Time\tWaiting Time\t Turnaround Time"
  48.  
  49. for (( i = 0; i < n; i++ )); do
  50.     tat[$i]=$((bt[$i]+wt[$i]))
  51.     total=$(($total+tat[$i]))
  52.     echo -e "${p[$i]}\t\t${bt[$i]}\t\t${wt[$i]}\t\t${tat[$i]}"
  53. done
  54.  
  55. avg_tat=$((total/n))
  56. echo "Average Wating Time = $avg_wt"
  57. echo "Avg Turnaround Time = $avg_tat"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement