Robert_JR

priority

Dec 14th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.55 KB | None | 0 0
  1. #!/bin/bash
  2. echo "Enter number of process"
  3. read n
  4.  
  5. echo "Enter process , AT , BT , Priority"
  6. for (( i = 1; i <= n; i++ ))
  7. do
  8.     read p[$i]
  9.     read at[$i]
  10.     read bt[$i]
  11.     read pr[$i]
  12. done
  13.  
  14. for(( i = 1; i <= n-1 ; i++))
  15. do
  16.     for(( j = 1; j <= n-i; j++))
  17.     do
  18.         if [ ${at[$j]} -gt ${at[$j+1]} ]
  19.         then
  20.             temp=${at[$j]}
  21.             at[$j]=${at[$j+1]}
  22.             at[$j+1]=$temp
  23.        
  24.             temp=${bt[$j]}
  25.             bt[$j]=${bt[$j+1]}
  26.             bt[$j+1]=$temp
  27.        
  28.             temp=${pr[$j]}
  29.             pr[$j]=${pr[$j+1]}
  30.             pr[$j+1]=$temp
  31.            
  32.        
  33.             temp=${p[$j]}
  34.             p[$j]=${p[$j+1]}
  35.             p[$j+1]=$temp
  36.         fi
  37.     done
  38. done
  39.  
  40. ct=`expr ${at[1]} + ${bt[1]} `
  41. tat=`expr $ct - ${at[1]} `
  42. wt[1]=`expr $tat - ${bt[1]} `
  43.  
  44. for(( i=2; i<=n-1; i++ ))
  45. do
  46.     for(( j=2; j<=n-1; j++ ))
  47.     do
  48.         if [ ${pr[$j]} -gt ${pr[$j+1]} ]
  49.         then
  50.            
  51.             temp=${at[$j]}
  52.             at[$j]=${at[$j+1]}
  53.             at[$j+1]=$temp
  54.    
  55.             temp=${bt[$j]}
  56.             bt[$j]=${bt[$j+1]}
  57.             bt[$j+1]=$temp
  58.    
  59.             temp=${p[$j]}
  60.             p[$j]=${p[$j+1]}
  61.             p[$j+1]=$temp
  62.    
  63.             temp=${pr[$j]}
  64.             pr[$j]=${pr[$j+1]}
  65.             pr[$j+1]=$temp
  66.         fi
  67.     done
  68. done
  69.  
  70. for(( i=2; i<=n; i++ ))
  71. do
  72.     ct=`expr $ct + ${bt[$i]} `
  73.     tat=`expr $ct - ${at[$i]} `
  74.     wt[i]=`expr $tat - ${bt[$i]} `
  75. done
  76.  
  77. twt=0
  78.  
  79. for(( i=1; i<=n; i++))
  80. do
  81.     twt=`expr $twt + ${wt[i]} `
  82. done
  83.  
  84. echo $twt
  85.  
  86. awt=`expr $twt / $n `
  87.  
  88. echo $awt
Advertisement
Add Comment
Please, Sign In to add comment