-
Notifications
You must be signed in to change notification settings - Fork 0
/
headers.h
133 lines (112 loc) · 2.97 KB
/
headers.h
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once
#include <stdio.h> //if you don't use scanf/printf change this include
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/msg.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <sys/resource.h>
#include <errno.h>
typedef short bool;
#define true 1
#define false 0
#define SHKEY 300
///==============================
// don't mess with this variable//
int *shmaddr; //
//===============================
int selected_algo;
int SJFflag = 0;
int RRquanta = 2;
int getClk()
{
return *shmaddr;
}
/*
* All process call this function at the beginning to establish communication between them and the clock module.
* Again, remember that the clock is only emulation!
*/
void initClk()
{
int shmid = shmget(SHKEY, 4, 0444);
while ((int)shmid == -1)
{
// Make sure that the clock exists
printf("Wait! The clock not initialized yet!\n");
sleep(1);
shmid = shmget(SHKEY, 4, 0444);
}
shmaddr = (int *)shmat(shmid, (void *)0, 0);
}
/*
* All process call this function at the end to release the communication
* resources between them and the clock module.
* Again, Remember that the clock is only emulation!
* Input: terminateAll: a flag to indicate whether that this is the end of simulation.
* It terminates the whole system and releases resources.
*/
void destroyClk(bool terminateAll)
{
shmdt(shmaddr);
if (terminateAll)
{
killpg(getpgrp(), SIGINT);
}
}
///================ Defined by Hodhod ==============
typedef struct
{
int id;
int arrival;
int runtime;
int priority;
///////
int pid;
int remainingtime;
int waitingtime;
int StartedBefore; // 1 means it was started before, 0 means it has never been started before
int status;
int memSize;
int memStart;
// possible status values:
// 1 ----> started
// 2 ----> resumed
// 3 ----> stopped
// 4 ----> finished
// int rem;
// int state; // You can make an enumerator later
// int sheduledAt; // the first time the process is scheduled
} process;
process *curentProcess=NULL;
typedef struct
{
int mtype; // 1 for messages to the scheduler
process proc;
// int id;
// int arrival;
// int runtime;
// int priority;
} msgbuff;
//===============================
typedef struct scheduling_algo{
void *type; //data structure
bool (*addProcess)(void *type, process *proc);//
bool (*preempt)(void *type);//if need change currant process
process *(*getNextProcess)(void *type); // get next process to run
bool (*removeProcess)(void *type, process *proc);//remove process
bool (*free)(void *type);//
/*void (*cast)(void *type);
*/
}scheduling_algo;
typedef struct {
long mtype;
process proc;
} msgBuf;
scheduling_algo algo;