-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu.c
More file actions
39 lines (25 loc) · 667 Bytes
/
cpu.c
File metadata and controls
39 lines (25 loc) · 667 Bytes
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
#include <stdio.h>
#include "kernel.h"
#include "interpreter.h"
#include <string.h>
#include "cpu.h"
#include "shell.h"
struct thisCPU CPU = { .quanta = 2 };
//execute processes
int runQuanta(int quanta) {
for (int i = 0; i < quanta; i++) {
if (ram[CPU.IP+i] == NULL){
return -1; // this instruction is NULL, which mean we dont want to enque anymore this pcb
}
strcpy(CPU.IR, ram[CPU.IP + i]);
if (pcbCounter != 0 && strstr(CPU.IR, "quit") != 0) { //exit only one script and continue the others
return -1;
}
parse(CPU.IR);
CPU.offset++;
if (CPU.offset==4){
return -2;
}
}
return 1;
}