SRTF Io
SRTF Io
SRTF Io
h>
#include <limits.h>
int main() {
int numProcesses;
// Input arrival, burst, and I/O wait times for each process
for (int i = 0; i < numProcesses; i++) {
printf("Enter arrival time of PID %d: ", i + 1);
scanf("%d", &arrivalTime[i]);
printf("Enter burst time of PID %d: ", i + 1);
scanf("%d", &burstTime[i]);
printf("Enter I/O wait time of PID %d: ", i + 1);
scanf("%d", &ioWaitTime[i]);
remainingTime[i] = burstTime[i]; // Initialize remaining time
completed[i] = 0; // Initialize completed status
}
// SRTF Scheduling
while (completedProcesses < numProcesses) {
int minIndex = -1;
int minRemainingTime = INT_MAX;
// Find the process with the smallest remaining time that has arrived
for (int i = 0; i < numProcesses; i++) {
if (arrivalTime[i] <= currentTime && !completed[i] && remainingTime[i]
< minRemainingTime) {
minRemainingTime = remainingTime[i];
minIndex = i;
}
}
if (minIndex != -1) {
// Execute the selected process for one unit of time
currentTime++;
remainingTime[minIndex]--;
return 0;
}