Shell Script To Demonstrate the Priority Scheduling Algorithm

Pranat
0
Lamp

 printf "Enter the Number of Processes :"

read size

for(( i=0; i<$size; i++ ))

do

printf "Enter the BURST TIME of Process $i :"

read ele

printf "Enter the PRIORITY! OF Process $i :"

read prior

process[ $i ]=$ele

priority[ $i ]=$prior

done

echo "------------------------------------"

printf "Processes are:${process[*]} " #Shortcut to Accees the Array Elements

printf "\n------------------------------------"

for(( i=0; i<$size; i++ ))

do

for(( j=i+1; j<$size; j++ ))

do

if [ ${priority[ $i ]} -gt ${priority[ $j ]} ]

then

temp=${priority[ $i ]}

priority[ $i ]=${priority[ $j ]}

priority[ $j ]=$temp

fi

if [ ${process[ $i ]} -gt ${process[ $j ]} ]

then

temp=${process[ $i ]}

process[ $i ]=${process[ $j ]}

process[ $j ]=$temp

fi

done

done

printf "\nThe Sorted Priority is ${priority[*]}"

printf "\n------------------------------------"

printf "\nProcesses in Gant Chart :${process[*]}"

# Waiting Time of the Process

temp=0

for(( i=0; i<$size; i++ ))

do

waiting[ $i ]=$temp

temp=`expr $temp + ${process[ $i ]}`

done

#To Display the Waiting Time of Teh Processesp

printf "\n------------------------------------"

printf "\nThe WAiting Time is : ${waiting[*]}"

echo ""

#Average Waiting Time

sum=0

for (( i=0; i<$size; i++ ))

do

sum=`expr $sum + ${waiting[ $i ]}`

done

cal=`expr $sum \/ $size`

echo "------------------------------------"

printf "The Average Waiting Time is :$cal ms \n"

echo "------------------------------------"

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !