fork(1) download
  1. #!/bin/bash
  2.  
  3. echo "Enter the process number"
  4. read n
  5. declare -a pid at bt ct tat wt rt vis srt
  6.  
  7. for((i=1;i<=n;i++))
  8. do
  9. pid[i]=$i
  10. read at[i]
  11. read bt[i]
  12. vis[i]=0
  13. done
  14.  
  15. time=0
  16. cc=0;
  17. while((cc<n))
  18. do
  19. mn=1000
  20. ind=-1
  21. for((i=1;i<=n;i++))
  22. do
  23. if(( vis[i]==0 && at[i]<=time))
  24. then
  25. if (( bt[i] < mn || (bt[i] == mn && at[i] < at[ind]) ))
  26. then
  27. mn=${bt[i]}
  28. ind=$i
  29. fi
  30. fi
  31. done
  32. if((ind==-1))
  33. then
  34. ((time++))
  35. else
  36. srt[ind]=$time
  37. time=$((time+bt[ind]))
  38. ct[ind]=$time
  39. tat[ind]=$((ct[ind]-at[ind]))
  40. wt[ind]=$((tat[ind]-bt[ind]))
  41. rt[ind]=$((srt[ind]-at[ind]))
  42. vis[ind]=1
  43. ((cc++))
  44. fi
  45. done
  46. #print all
  47. echo -e "\nPID\tAT\tBT\tCT\tTAT\tWT\tRT"
  48. for (( i=1; i<=n; i++ ))
  49. do
  50. echo -e "P${pid[i]}\t${at[i]}\t${bt[i]}\t${ct[i]}\t${tat[i]}\t${wt[i]}\t${rt[i]}"
  51. done
  52.  
  53.  
  54.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Enter the process number

PID	AT	BT	CT	TAT	WT	RT