-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
108 lines (101 loc) · 2.84 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "textmenu.h"
#include "process.h"
#include "message.h"
#include "semaphore.h"
/*
Main
PCB's and Process Scheduling Simulation
Interactive OS simulating basic functions
Receives keyboard inputs and output reports to screen
Has Process, Messsaging and Semaphore Commands
*/
int main () {
int priority;
int pid;
Message * message;
int sid;
int svalue;
if (Process_setup() != 0) {
printInvalidSetup();
return 1;
}
if (Message_setup() != 0) {
printInvalidSetup();
return 1;
}
if (Sempahore_setup() != 0) {
printInvalidSetup();
return 1;
}
printIntroduction();
while (!Process_isInitExited()) {
char input = inputChar();
switch (input) {
case 'C':
priority = inputPriorityInt();
pid = Process_create(priority);
printCreateReport(pid);
break;
case 'F':
pid = Process_fork();
printForkReport(pid);
break;
case 'K':
pid = inputPID();
pid = Process_kill(pid);
printKillReport(pid);
break;
case 'E':
pid = Process_exit();
printExitReport(pid);
break;
case 'Q':
pid = Process_quantum();
printQuantumReport(pid);
break;
case 'S':
pid = inputPID();
message = inputMessage();
pid = Message_send(pid, message);
printSendReport(pid);
break;
case 'R':
pid = Message_receive();
printReceiveReport(pid);
break;
case 'Y':
pid = inputPID();
message = inputMessage();
pid = Message_reply(pid, message);
printReplyReport(pid);
break;
case 'N':
sid = inputSID();
svalue = inputSValue();
sid = Semaphore_new(sid, svalue);
printSemaphoreNewReport(sid, svalue);
break;
case 'P':
sid = inputSID();
sid = Semaphore_p(sid);
printSemaphorePReport(sid);
break;
case 'V':
sid = inputSID();
sid = Semaphore_v(sid);
printSemaphoreVReport(sid);
break;
case 'I':
pid = inputPID();
procinfo(pid);
break;
case 'T':
totalinfo();
break;
default:
printInvalidCommand();
break;
}
printProcessChange();
}
}