SRTF
SRTF
h>
#include <limits.h>
int main() {
int numProcesses;
// Find the process with the smallest remaining time that has arrived
for (int i = 0; i < numProcesses; i++) {
if (arrivalTime[i] <= time && !completed[i] && remainingTime[i] <
minRemainingTime) {
minRemainingTime = remainingTime[i];
minIndex = i;
}
}
if (minIndex != -1) {
// Execute the selected process for one unit of time
time++;
remainingTime[minIndex]--;
// Calculate averages
float totalWaitingTime = 0, totalTurnaroundTime = 0;
printf("PID\tArrival\tBurst\tCompletion\tTAT\tWait\n");
for (int i = 0; i < numProcesses; i++) {
printf("%d\t%d\t%d\t%d\t\t%d\t%d\n",
i + 1,
arrivalTime[i],
burstTime[i],
completionTime[i],
turnaroundTime[i],
waitingTime[i]);
totalWaitingTime += waitingTime[i];
totalTurnaroundTime += turnaroundTime[i];
}
return 0;
}