-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.c
106 lines (97 loc) · 2.43 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
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
#define power 1e9
pid_t pida, pidb, pidc;
struct timespec start_a, finish_a, start_b, finish_b, start_c, finish_c;
double time_store_a;
double time_store_b;
double time_store_c;
FILE *file;
void count(int policy_name)
{
if (policy_name == 0)
{
nice(0);
sched_setscheduler(getpid(), SCHED_OTHER, NULL);
execl("./Process1", "Process1", NULL, NULL);
}
else if (policy_name == 1)
{
//nice(0);
sched_setscheduler(getpid(), SCHED_RR, NULL);
execl("./Process2", "Process2", NULL, NULL);
}
else if (policy_name == 2)
{
//nice(0);
sched_setscheduler(getpid(), SCHED_FIFO, NULL);
execl("./Process3", "Process3", NULL, NULL);
}
}
signed main()
{
int graph_banau = 0;
clock_gettime(0, &start_a);
pida = fork();
if (pida == 0)
{
count(0);
}
else if (pida > 0)
{
clock_gettime(0, &start_b);
pidb = fork();
if (pidb == 0)
{
count(1);
}
else if (pidb > 0)
{
clock_gettime(0, &start_c);
pidc = fork();
if (pidc == 0)
{
count(2);
}
else if (pidc > 0)
{
int w3 = wait(NULL);
clock_gettime(0, &finish_c);
graph_banau++;
}
else
{
perror("fork error");
}
int w2 = wait(NULL);
clock_gettime(0, &finish_b);
graph_banau++;
}
else
{
perror("fork error");
}
int w1 = wait(NULL);
clock_gettime(0, &finish_a);
graph_banau++;
}
else
{
perror("fork error");
}
file = fopen("file.txt", "w");
fprintf(file, "SCHED_OTHER %lf\n", finish_a.tv_sec - start_a.tv_sec + (finish_a.tv_nsec - start_a.tv_nsec) / power);
fprintf(file, "SCHED_RR %lf\n", finish_b.tv_sec - start_b.tv_sec + (finish_b.tv_nsec - start_b.tv_nsec) / power);
fprintf(file, "SCHED_FIFO %lf\n", finish_c.tv_sec - start_c.tv_sec + (finish_c.tv_nsec - start_c.tv_nsec) / power);
fclose(file);
if (graph_banau == 3)
{
system("python3 Graph.py");
}
return 0;
}