-
Notifications
You must be signed in to change notification settings - Fork 1
/
myMemTest.c
81 lines (66 loc) · 1.85 KB
/
myMemTest.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
#include "types.h"
#include "stat.h"
#include "user.h"
#define PGSIZE 4096
#define LOOPLENGTH 15
/*********************** MAIN ***********************/
int main(int argc, char *argv[])
{
int i, j, num;
int pid = 0;
char * Fmem[LOOPLENGTH];
char input[5];
printf(1,"\n\n*************** myMemTest : START ***************\n\n");
for (i = 0; i < LOOPLENGTH - 3; i++)
{
Fmem[i] = sbrk(PGSIZE);
*Fmem[i] = i;
}
for (i = 100; i < 120; i++)
{
*Fmem[(i % 3)] = i;
printf(1, "*Fmem[%d] was accessed in tick %d\n", i % 3, uptime());
}
for (i = LOOPLENGTH - 3; i < LOOPLENGTH; i++)
{
printf(1,"\nPress enter to continue \n");
gets(input,5);
Fmem[i] = sbrk(PGSIZE);
*Fmem[i] = i;
}
printf(1,"\n\n*********** myMemTest : FINISHED sbrking ***********\n");
printf(1,"\n\n*********** myMemTest : Performing fork() ***********\n\n");
if((pid = fork()) < 0)
{
printf(1,"Fork operation failed\n");
}
else if (pid == 0)
{
for(j = 0; j < LOOPLENGTH; j++)
{
if(Fmem[j])
{
printf(1,"\nPress enter to continue \n");
gets(input,5);
num = j + 50;
*Fmem[j] = num;
printf(1,"Process %d: Fmem[%d] is %d \n", getpid(), j, (int)*(Fmem[j]));
}
}
exit();
}
else
{
wait();
for(j = 0; j < LOOPLENGTH; j++)
{
if(Fmem[j])
{
printf(1,"\nPress enter to continue \n");
gets(input,5);
printf(1,"Process %d: Fmem[%d] is %d \n", getpid(), j, (int)*(Fmem[j]));
}
}
exit();
}
}