30/03/2023

Preemptive Priority Scheduling Program in C++ With Arrival Time

Write a Preemptive Priority Scheduling Program in C++ With Arrival Time. Preemptive priority scheduling C++  with Gantt Chart. Preemptive scheduling hackerrank solution. Priority scheduling in OS.

Preemptive Priority Scheduling Program in C++ With Arrival Time

Preemptive Priority Scheduling Program in C++ With Arrival Time


#include <cstdio>
#include <conio.h>
#include <iostream>
/* Preemptive Priority Scheduling C++  with Gantt Chart*/
int main()
{
	int x, n, p[10], pp[10], pt[10], w[10], t[10], awt, atat, i;
	printf("Enter the Number of Process: ");
	scanf("%d", &n);
	
	printf("\n Enter Process : Time Priorities \n");
	for (i = 0; i < n; i++)
	{
		printf("\nProcess no %d : ", i + 1);
		scanf("%d  %d", &pt[i], &pp[i]);
		p[i] = i + 1;
	}

	for (i = 0; i < n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (pp[i] < pp[j])
			{
				x = pp[i];
				pp[i] = pp[j];
				pp[j] = x;
				x = pt[i];
				pt[i] = pt[j];
				pt[j] = x;
				x = p[i];
				p[i] = p[j];
				p[j] = x;
			}
		}
	}

	w[0] = 0;
	awt = 0;
	t[0] = pt[0];
	atat = t[0];
	for (i = 1; i < n; i++)
	{
		w[i] = t[i - 1];
		awt += w[i];
		t[i] = w[i] + pt[i];
		atat += t[i];
	}

	printf("\n\n Job \t Burst Time \t Wait Time \t Turn Around Time   Priority \n");
	for (i = 0; i < n; i++)
		printf("\n %d \t\t %d  \t\t %d \t\t %d \t\t %d \n", p[i], pt[i], w[i], t[i], pp[i]);
	awt /= n;
	atat /= n;
	printf("\n Average Wait Time : %d \n", awt);
	printf("\n Average Turn Around Time : %d \n", atat);
	getch();
}

The Output of the Priority Scheduling Program


The Output of the Priority Scheduling Program

Similar to Priority Scheduling


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: