IMPLEMENTATION REPORT
SCHEDULING
Scheduling is the process of arranging, controlling and optimizing work in a production
process or manufacturing process. Scheduling is used to allocate resources.
Priority Scheduling is a method of scheduling processes that is based on priority. In this
algorithm, the scheduler selects the tasks to work as per the priority. Processes with same
priority are executed in FCFS manner.
Different types of Priority scheduling are:
1. Preemptive Priority Scheduling: If the new process arrived at the ready queue
has a higher priority than the currently running process, the CPU is preempted,
which means the processing of the current process is stopped and the incoming
new process with higher priority gets the CPU for its execution.
2. Non-Preemptive Priority Scheduling: In case of non-preemptive priority
scheduling algorithm if a new process arrives with a higher priority than the
current running process, the incoming process is put at the head of the ready
queue, which means after the execution of the current process it will be processed.
Criteria for scheduling process are:
1.CPU Utilization: CPU utilization refers to a computer's usage of processing resources.
Ideally CPU would be busy 100% of time.
2.Throughput: Number of processes completed per unit time.
3.Turn around time: Time required for a particular process to complete.
4.Waiting time: Time spent by the processes in the ready queue waiting for its turn to get
on CPU.
Advantages of Priority Scheduling are:
• The priority of process is selected on the basis of memory requirement, user
preference or the requirement of time.
• Processes are executed on the basis of priority. So high priority does not need to
wait for long which saves time.
• It is a user friendly algorithm.
• Simple to understand.
• CPU does every sharing. It completes every process.
• Priority scheduling in preemptive mode is best suited for real time operating
system.
Limitations of priority scheduling are:
1. In priority scheduling algorithm, there are chances for indefinite blocking
or starvation.A process is considered blocked when it is ready to run but has to
wait for the CPU as some other process is running currently.
But in case of priority scheduling if new higher priority processes keep coming in
the ready queue then the processes waiting in the ready queue with lower priority
might have to wait for long time before getting the CPU for execution.
In 1973, when the IBM 7904 machine was shut down at MIT, a low-priority
process was found which was submitted in 1967 and had not yet been run.
One possible solution is aging.
To prevent starvation of any process, aging concept can be used where priorities
are kept on increasing the low-priority process based on the its waiting time. Aging
process ensures that no process will have to wait for indefinite time for getting
CPU time for processing.
2. If the system crashes eventually, then all the processes having low priority which
are not finished yet, also get lost.
IMPLEMENTATION:
Abbreviations used in the code are:
et: Execution time or burst time
at: arrival time
n: number of processes
ft and st are temporary array used for calculating turn around time
temp:temporary variable
pn: array used to store process name
wt: wait time
tat: turn around time
totta: total turn around
totwt :total wait time
awt: average wait time
ata: average turn around time
t: extra array to copy process
p: priority
i and j are loop variables
CODE
#include<stdio.h>
#include<string.h>
int main()
int et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[10];
int totwt=0,totta=0;
float awt,ata;
char pn[10][10],t[10];
printf("Enter the number of process:");
scanf("%d",&n);
for(i=0; i<n; i++)
printf("Enter process name,arrival time,execution time & priority for process
%d:",i+1);
scanf("%s%d%d%d",pn[i],&at[i],&et[i],&p[i]);
}
for(i=0; i<n; i++)
for(j=0; j<n; j++)
if(p[i]<p[j])
temp=p[i];
p[i]=p[j];
p[j]=temp;
temp=at[i];
at[i]=at[j];
at[j]=temp;
temp=et[i];
et[i]=et[j];
et[j]=temp;
strcpy(t,pn[i]);
strcpy(pn[i],pn[j]);
strcpy(pn[j],t);
for(i=0; i<n; i++)
if(i==0)
{
st[i]=at[i];
wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
else
st[i]=ft[i-1];
wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
totwt+=wt[i];
totta+=ta[i];
awt=(float)totwt/n;
ata=(float)totta/n;
printf("\nProcess Name\tArrival Time\tExecution Time\tPriority\tWaiting Time\tta
time");
for(i=0; i<n; i++)
printf("\n%s\t\t%5d\t\t%5d\t\t%5d\t\t%5d\t\t%5d",pn[i],at[i],et[i],p[i],wt[i],ta[i]);
printf("\nAverage waiting time is:%f",awt);
printf("\nAverage turn around time is:%f",ata);
return 0;
}
OUTPUT
CONCLUSION
Priority scheduling is a non-pre emptive algorithm and one of the most commonly
used scheduling algorithms in batch operating systems. Each process is assigned with
a priority. Process with the highest priority is executed first and so on. Processes with
same priority are executed on first come first served (FCFS) basis. Priority can be
decided based on memory requirements, time requirements or any other resource
requirements.