4.priority Scheduling
4.priority Scheduling
4.priority Scheduling
Description: In this algorithm, processes are scheduled based on their priority, and no process should
wait for more than 10 seconds. If a process has been waiting for more than 10 seconds, it will be
executed for at least 1 second before going back to the waiting queue. The priority scheduling algorithm
with the specified conditions and prints the execution order of processes.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
if (highest_priority_index == -1) {
// No process can be scheduled, so just increment the time
current_time++;
} else {
if (processes[highest_priority_index].burst_time > 10) {
current_time += 10;
processes[highest_priority_index].burst_time -= 10;
processes[highest_priority_index].wait_time += 10;
printf("Process %c executed for 10 seconds at time %d\n",
processes[highest_priority_index].name, current_time);
} else {
current_time += processes[highest_priority_index].burst_time;
processes[highest_priority_index].wait_time += processes[highest_priority_index].burst_time;
printf("Process %c executed for %d seconds at time %d\n",
processes[highest_priority_index].name,
processes[highest_priority_index].burst_time, current_time);
processes[highest_priority_index].burst_time = 0;
n--;
}
}
}
}
int main() {
struct Process processes[] = {
{'P', 1, 25, 0},
{'Q', 2, 15, 0},
{'R', 3, 10, 0},
};
int n = sizeof(processes) / sizeof(processes[0]);
priority_scheduling(processes, n);
return 0;
}
Sample output
Result