-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheaders.h
executable file
·92 lines (76 loc) · 1.94 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
// Include header.h file in any other file uses clk
#ifndef HEADER
#define HEADER
// Includes
#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 <math.h>
// Type definitions
typedef short bool;
#define true 1
#define false 0
#define SHKEY 300
enum Status { STARTED, RESUMED, STOPPED, FINISHED };
// Process struct
struct Process {
int id;
int pid;
int arrivalTime;
int priority;
int runningTime;
int remainingTime;
int waitingTime;
int finishTime;
enum Status status; //? Can be modified
// TODO Add any process-related data
};
///==============================
//don't mess with this variable//
int * shmaddr; //
//===============================
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);
}
}
#endif