top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is Priority Based Scheduling for processes in an Operating System, please explain with detail?

+3 votes
756 views
What is Priority Based Scheduling for processes in an Operating System, please explain with detail?
posted Jul 15, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

A priority based scheduling algorithm is an algorithm in which a priroity is associated with each process, and the CPU is allocated to the process with the highest priority (Equal-priority processes are scheduled in FCFS order).

PRIORITY BASED SCHEDULING:

• Assign each process a priority. Schedule highest priority first. All processes within same priority are FCFS.
• Priority may be determined by user or by some default mechanism. The system may determine the priority based on memory requirements, time limits, or other resource usage.
• Starvation occurs if a low priority process never runs. Solution: build aging into a variable priority.
• Delicate balance between giving favorable response for interactive jobs, but not starving batch jobs.

Alternate Approach

  • Each process is assigned a priority. Process with highest priority is to be executed first and so on.
  • Processes with same priority are executed on first come first serve basis.
  • Priority can be decided based on memory requirements, time requirements or any other resource requirement.

Example
enter image description here

Wait time of each process is following

Process Wait Time : Service Time - Arrival Time
P0 9 - 0 = 9
P1 6 - 1 = 5
P2 14 - 2 = 12
P3 0 - 0 = 0

Average Wait Time: (9+5+12+0) / 4 = 6.5

answer Jul 24, 2015 by Mohammed Hussain
0 votes

What is Priority Based scheduling
A priority based scheduling algorithm is an algorithm in which a priroity is associated with each process, and the CPU is allocated to the process with the highest priority (Equal-priority processes are scheduled in FCFS order).

Advantage of Priority based Scheduling
1. Simplicity.
2. Reasonable support for priority.
3. Suitable for applications with varying time and resource requirements.

Disadvantages of Priority based Scheduling
1. Indefinite blocking or starvation if high priority process keeps on coming.
2. A priority scheduling can leave some low priority waiting processes indefinitely for CPU.
3. If the system eventually crashes then all unfinished low priority processes gets lost.
To counter this most of the PBS based OS increase the priority of process in waiting queue after every certain interval.

C Program to show Priority Based Scheduling

#include<stdio.h>

void main()
{
    int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp;
    int average_waiting_time,average_turnaround_time;

    printf("Enter Total Number of Process:");
    scanf("%d",&n);

    printf("nEnter Burst Time and Priorityn");
    for(i=0;i<n;i++)
    {
        printf("nP[%d]n",i+1);
        printf("Burst Time:");
        scanf("%d",&bt[i]);
        printf("Priority:");
        scanf("%d",&pr[i]);
        p[i]=i+1;           //P[i] contains process number
    }

    //sorting burst time, priority and process number in ascending order using selection sort
    for(i=0;i<n;i++)
    {
        pos=i;
        for(j=i+1;j<n;j++)
        {
            if(pr[j]<pr[pos])
                pos=j;
        }

        temp=pr[i];
        pr[i]=pr[pos];
        pr[pos]=temp;

        temp=bt[i];
        bt[i]=bt[pos];
        bt[pos]=temp;

        temp=p[i];
        p[i]=p[pos];
        p[pos]=temp;
    }

    wt[0]=0;  //waiting time for first process is zero

    //calculate waiting time
    for(i=1;i<n;i++)
    {
        wt[i]=0;
        for(j=0;j<i;j++)
            wt[i]+=bt[j];

        total+=wt[i];
    }

    average_waiting_time=total/n;     
    total=0;

    printf("nProcesst    Burst Time    tWaiting TimetTurnaround Time");
    for(i=0;i<n;i++)
    {
        tat[i]=bt[i]+wt[i];     //calculate turnaround time
        total+=tat[i];
        printf("nP[%d]tt  %dtt    %dttt%d",p[i],bt[i],wt[i],tat[i]);
    }

    average_turnaround_time=total/n;  
    printf("nnAverage Waiting Time=%d", average_waiting_time);
    printf("nAverage Turnaround Time=%dn", average_turnaround_time);
}
answer Jul 24, 2015 by Salil Agrawal
...