6/recent/ticker-posts

OS Priority Scheduling 1

Write a C program to list the processes according to their priority given the process names, burst time of the processes and the priority of the processes. Assume that all processes arrive at time t0. The process names are of type character array, burst time and priority of type integers.


Input and Output format :
Refer Sample Input and Output for formatting specifications.


Sample Input and Output :
[All text in bold corresponds to the input and the rest corresponds to output] 


Enter the name of process 1
A
Enter the burst time of process 1
5
Enter the priority of process 1
2
Enter the name of process 2
B
Enter the burst time of process 2
6
Enter the priority of process 2
1
Process Details
B, A

Answer: 

#include<stdio.h>
int main()
{
    struct process{
        char name;
        int pt;
        int bt;
    }p[2];
    
    for(int i=0;i<2;i++)
    {
        printf("Enter the name of process %d\n",i+1);
        scanf("%s",&p[i].name);
        printf("Enter the burst time of process %d\n",i+1);
        scanf("%d",&p[i].bt);
        printf("Enter the priority of process %d\n",i+1);
        scanf("%d",&p[i].pt);
    }
    printf("Process Details\n");
    if(p[0].pt>p[1].pt)
    {
        printf("%s, %s",&p[1].name,&p[0].name);
    }
    else
    {
        printf("%s, %s",&p[0].name,&p[1].name);
    }
}

Post a Comment

0 Comments