-
Notifications
You must be signed in to change notification settings - Fork 0
/
testgsp.c
161 lines (144 loc) · 4.39 KB
/
testgsp.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// FILE - testgsp.c
#include "types.h"
#include "user.h"
#define NULL ((void *)0)
// struct news{
// int test;
// };
// int main(int argc, char *argv[])
// {
// char *test = "hello";
// void *addr = (void *)getsharedpage("Hello", 10);
// struct news *news1 = (struct news *)addr;
// news1->test = 1;
// printf(1, "Address : %p\n", addr);
// printf(1, "String address : %p\n", test);
// printf(1, "news1 test : %d\n", news1->test);
// exit();
// }
// typedef struct{
// // char * name;
// int age;
// }student_info;
// int main(int argc, char *argv[])
// {
// void *parent_addr = (void *)getsharedpage("Hello", 1);
// int * test1 = (int *)parent_addr;
// *test1 = 1000;
// printf(1, " 1 : %d\n", *test1);
// int pid = fork();
// if(pid < 0){
// printf(1, "Failed to fork, exiting...\n");
// exit();
// }
// if(pid == 0){
// // void *child_addr =
// // (void *)
// // getsharedpage("Hello", 1);
// // char * test = (char *)child_addr;
// // printf(1, " 3 : %c\n", *test);
// // student_info * st_info_child = (student_info *)child_addr;
// // // st_info_child->name = "Nithin Rao";
// // st_info_child->age = 23;
// // printf(1, "Student Age : %d\n", st_info_child->age);
// printf(1, "Assigned\n");
// }else{
// wait();
// // student_info * st_info = (student_info *)parent_addr;
// // printf(1, "Student Name : %s\n", st_info->name);
// // printf(1, "Student Age : %d\n", st_info->age);
// printf(1, " 2 : %d\n", *test1);
// }
// exit();
// }
// int main(int argc, char *argv[])
// {
// void *parent_addr = (void *)getsharedpage("Hello", 1);
// int * test1 = (int *)parent_addr;
// *test1 = 1000;
// printf(1, " 1 : %d\n", *test1);
// printf(1, " 1.1 : %x\n", test1);
// int pid = fork();
// if(pid < 0){
// printf(1, "Failed to fork, exiting...\n");
// exit();
// }
// if(pid == 0){
// printf(1, " 2 : %d\n", *test1);
// printf(1, " 2.1 : %x\n", test1);
// void *child_addr = (void *)getsharedpage("Hello", 1);
// int * test = (int *)child_addr;
// printf(1, " 3 : %d\n", *test);
// printf(1, " 3.1 : %x\n", test);
// *test = 2000;
// printf(1, " 4 : %d\n", *test);
// // void *child_addr2 = (void *)getsharedpage("Hello", 1);
// // int * test2 = (int *)child_addr2;
// // printf(1, " 2 : %d\n", *test2);
// // printf(1, "Assigned\n");
// if(freesharedpage("Hello")){
// printf(1, "freesharedpage call succeeded!\n");
// }
// }else{
// wait();
// void *parent_addr = (void *)getsharedpage("Hello", 1);
// int * test1 = (int *)parent_addr;
// printf(1, " 5 : %d\n", *test1);
// printf(1, " 6 : %x\n", test1);
// }
// exit();
// }
int main(int argc, char *argv[]) {
// void *parent_addr = (void *)getsharedpage("Hello", 1);
// int * test1 = (int *)parent_addr;
// *test1 = 1000;
// printf(1, " 1 : %d\n", *test1);
// printf(1, " 1.1 : %x\n", test1);
int p = getsharedpage("HelloWorld", 2);
int *test= (int *)p;
*test = 2;
int t = 100;
int *x = &t;
printf(1, "Parent : %x, %d, %x, %d\n", test, *test, x, *x);
int pid1 = fork();
if (pid1 < 0) {
printf(1, "Failed to fork(1), exiting...\n");
exit();
}
if (pid1 == 0) {
int pid2 = fork();
if (pid2 < 0) {
printf(1, "Failed to fork(2), exiting...\n");
exit();
}
if (pid2 == 0) {
p = getsharedpage("HelloWorld", 2);
test = (int *)p;
*test = 30;
*x = 130;
printf(1, "Grand Child : %x, %d, %x, %d\n", test, *test, x, *x);
if (freesharedpage("HelloWorld")==0) {
printf(1, "freesharedpage(1) call succeeded!\n");
}
} else {
wait();
p = getsharedpage("HelloWorld", 2);
test = (int *)p;
// *test = 40;
*x = 140;
printf(1, "Child : %x, %d, %x, %d\n", test, *test, x, *x);
if (freesharedpage("HelloWorld")==0) {
printf(1, "freesharedpage(2) call succeeded!\n");
}
}
} else {
wait();
p = getsharedpage("HelloWorld", 2);
test = (int *)p;
printf(1, "Parent : %x, %d, %x, %d\n", test, *test, x, *x);
if (freesharedpage("HelloWorld")==0) {
printf(1, "freesharedpage(3) call succeeded!\n");
}
}
exit();
}