lab-06-Rushilwiz/main.c
github-classroom[bot] 05ecbee94d
Initial commit
2024-04-15 17:24:16 +00:00

67 lines
1.7 KiB
C

// Do not edit this file
// Usage (after running make): ./main
// This file takes input from stdin and outputs to stdout. No CLI args
#include <stdio.h>
#include <stdlib.h>
#include "schedule.h"
#include "task.h"
int main() {
int n;
printf("Number of tasks: ");
scanf("%d", &n);
if (n <= 0) {
fprintf(stderr, "Number of tasks must be greater than 0\n");
return EXIT_FAILURE;
}
unsigned int pid, priority, cycles;
for (int i = 0; i < n; i++) {
printf("pid priority cycles: ");
scanf("%d %d %d", &pid, &priority, &cycles);
if (!append_task(pid, priority, cycles)) {
fprintf(stderr, "Append failed, is %d a duplicate pid?\n", pid);
return EXIT_FAILURE;
}
}
printf("---- Tasks ----\n");
printf("(num_tasks) [pid:priority:cycles:priority/cycles ...]\n");
print_tasks();
printf(
"Select scheduling algorithm (0: Display min heap, 1: FCFS, "
"2: Priority queue, 3: "
"Round robin): ");
int scheduler = 0;
scanf("%d", &scheduler);
switch (scheduler) {
case 0:
printf("---- Min heap ----\n");
min_heapify();
print_tasks();
break;
case 1:
printf("---- FCFS ----\n");
fcfs();
break;
case 2:
printf("---- Priority queue ----\n");
priority_queue(QUANTUM);
break;
case 3:
printf("---- Round robin ----\n");
round_robin(QUANTUM);
break;
default:
fprintf(stderr, "Invalid scheduler\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}