Thread: Problem with Priority Non-Preemptive Scheduling

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    5

    Problem with Priority Non-Preemptive Scheduling

    Where should I insert the arrival time and the burst time in the calculation? In this program, the arrival time,burst time and priority must be enter by the user.and the Average waiting time and average turnaround time must be display at the end of the program.please help

    Code:
    #include<stdio.h>
    
    
    int i,j,n;
    float totwt;
    
    
    struct pr
        {
            char name[5];
            int arrival,burst;
            int priority;
            float twait;
            float trnd;
        };
        struct pr temp;
        struct pr pr1[20];
    void init()
    {
        printf("\nEnter the number of processes:");
        scanf("%d",&n);
       
        for(i=0;i<n;i++)
        {
            printf("\nEnter the details of process %d:\n1.Name: ",i+1);
            scanf("%s",pr1[i].name);
            printf("2.Arrival time: ");
            scanf("%d",&pr1[i].arrival);
            printf("3.Burst Time: ");
            scanf("%d",&pr1[i].burst);
            printf("4.Priority: ");
            scanf("%d",&pr1[i].priority);
        }
    }
    void prioritysort()
    {
        for(i=0;i<n;i++)
        for(j=0;j<n-i-1;j++)
        {
            if(pr1[j].priority>pr1[j+1].priority)
            {
                temp=pr1[j];
                pr1[j]=pr1[j+1];
                pr1[j+1]=temp;
            }
        }
    }
    
    
    void calculation()
    {
    pr1[0].twait=0;
    totwt=0;
    totserv=pr1[0].trnd=pr1[0].tservice;
        for(i=1;i<n;i++)
        {
            //printf("\nwait= %f",totwt);
            pr1[i].twait=pr1[i-1].twait+pr1[i-1].tservice;
            totwt+=pr1[i].twait;
            pr1[i].trnd=pr1[i].twait+pr1[i].tservice;
            totserv+=pr1[i].trnd;
    
    
        }
    }
    void printing()
    {
        printf("Name \tPriority \tArrival Time \tBurst Time \tWaitTime \tTurnAroundTime\n");
        for(i=0;i<n;i++)
            {
            printf("%s \t %d \t\t &d \t%d \t %f \t %f\n",pr1[i].name,pr1[i].priority,pr1[i].arrival,pr1[i].burst,pr1[i].twait,pr1[i].trnd);
            }
            printf("\nAverage wait:%f \tAverage turnaround:%f \n",totwt/n,totserv/n);
    }

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    More copypasta.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SJF Scheduling Problem
    By IT_ in forum C Programming
    Replies: 12
    Last Post: 12-08-2011, 10:40 AM
  2. Exam Scheduling Problem
    By itsacezon in forum C Programming
    Replies: 4
    Last Post: 10-19-2011, 09:52 AM
  3. Writing a preemptive multitasking system
    By caesius in forum C Programming
    Replies: 1
    Last Post: 08-07-2010, 08:05 AM
  4. Problem implementing priority queue using array
    By lazyme in forum C Programming
    Replies: 10
    Last Post: 11-24-2009, 10:57 AM