-
Notifications
You must be signed in to change notification settings - Fork 0
/
FIFO.c
40 lines (33 loc) · 791 Bytes
/
FIFO.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <sys/syscall.h>
#include <sys/wait.h>
#include <stdbool.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "policy.h"
void FIFO(int procNum) {
sortReady(procNum);
#ifdef DEBUG
for(int i = 0; i < procNum; i++)
printf("--%s %d %d\n", proc[i]->name, proc[i]->ready, proc[i]->exec);
#endif
int createdNum = 0;
for (int time = 0; createdNum < procNum; ++time) {
while (createdNum < procNum && time == proc[createdNum]->ready) {
createChild(createdNum, 99 - createdNum);
++createdNum;
}
unitTime();
#ifdef DEBUG
if (time % 100 == 0)
fprintf(stderr, "[%d] time = %d\n", getpid(), time);
#endif
}
waitProcess(procNum);
printInfo(procNum);
return;
}