-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit0.c
More file actions
152 lines (141 loc) · 5.26 KB
/
Copy pathinit0.c
File metadata and controls
152 lines (141 loc) · 5.26 KB
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
#include <comp421/hardware.h>
#include <comp421/yalnix.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int x = 5;
int y = 34;
char s2[10] = "Help!";
int main(int argc, char **argv) {
(void)argc;
(void)argv;
// int i;
// for (i = 0; i < argc; i++) {
// fprintf(stderr, "argv[%d] = %p", i, argv[i]);
// fprintf(stderr, " = '%s'\n", argv[i]);
//}
// TracePrintf(0, "Init is working\n");
// int z = y - x;
// TracePrintf(0, "Result is %i\n", z);
// //Test Brk()
// char *s = malloc(sizeof(char)*20000);
// if (s == NULL) {
// TracePrintf(0, "Pointer is null!\n");
// } else {
// strcpy(s, s2);
// TracePrintf(0, "Malloced string: %s\n", s);
// }
//Test GetPid()
(void)argc;
TracePrintf(0, "PID of the current process: %i\n", GetPid());
// Test Delay()
// TracePrintf(0, "1st delay return value is %i pid=%i\n", Delay(5), GetPid());
// int pid1 = Fork();
// if(pid1 == 0) {
// TracePrintf(0, "Fork1: I'm child: %i\n", GetPid());
// TracePrintf(0, "I'm starting a new program\n");
// // Exec(argv[1], argv + 1);
// } else if (pid1 > 0) {
// TracePrintf(0, "Fork1: I'm parent: %i\n", GetPid());
// int pid2 = Fork();
// if(pid2 == 0) {
// TracePrintf(0, "Fork2: I'm child: %i\n", GetPid());
// // Exec(argv[1], argv + 1);
// } else if (pid2 > 0) {
// TracePrintf(0, "Fork2: I'm parent: %i\n", GetPid());
// Delay(8);
// TracePrintf(0, "Delay ended for pid=%i\n", GetPid());
// } else {
// TracePrintf(0, "Fork failed\n");
// }
// } else {
// TracePrintf(0, "Fork failed\n");
// }
int p1 = Fork();
if(p1 == 0) {
TracePrintf(0, "Fork1: I'm child: %i\n", GetPid());
TracePrintf(0, "I'm starting a new program\n");
// Exec(argv[1], argv + 1);
} else if (p1 > 0) {
TracePrintf(0, "Fork1: I'm parent: %i\n", GetPid());
} else {
TracePrintf(0, "Fork failed\n");
}
p1 = Fork();
if(p1 == 0) {
TracePrintf(0, "Fork1: I'm child: %i\n", GetPid());
TracePrintf(0, "I'm starting a new program\n");
// Exec(argv[1], argv + 1);
} else if (p1 > 0) {
TracePrintf(0, "Fork1: I'm parent: %i\n", GetPid());
} else {
TracePrintf(0, "Fork failed\n");
}
p1 = Fork();
if(p1 == 0) {
TracePrintf(0, "Fork1: I'm child: %i\n", GetPid());
TracePrintf(0, "I'm starting a new program\n");
// Exec(argv[1], argv + 1);
} else if (p1 > 0) {
TracePrintf(0, "Fork1: I'm parent: %i\n", GetPid());
} else {
TracePrintf(0, "Fork failed\n");
}
p1 = Fork();
if(p1 == 0) {
TracePrintf(0, "Fork1: I'm child: %i\n", GetPid());
TracePrintf(0, "I'm starting a new program\n");
// Exec(argv[1], argv + 1);
} else if (p1 > 0) {
TracePrintf(0, "Fork1: I'm parent: %i\n", GetPid());
} else {
TracePrintf(0, "Fork failed\n");
}
p1 = Fork();
if(p1 == 0) {
TracePrintf(0, "Fork1: I'm child: %i\n", GetPid());
TracePrintf(0, "I'm starting a new program\n");
// Exec(argv[1], argv + 1);
} else if (p1 > 0) {
TracePrintf(0, "Fork1: I'm parent: %i\n", GetPid());
} else {
TracePrintf(0, "Fork failed\n");
}
// p1 = Fork();
// if(p1 == 0) {
// TracePrintf(0, "Fork1: I'm child: %i\n", GetPid());
// TracePrintf(0, "I'm starting a new program\n");
// // Exec(argv[1], argv + 1);
// } else if (p1 > 0) {
// TracePrintf(0, "Fork1: I'm parent: %i\n", GetPid());
// } else {
// TracePrintf(0, "Fork failed\n");
// }
// if(Fork() == 0) {
// TracePrintf(0, "Fork2: I'm child: %i\n", GetPid());
// TracePrintf(0, "I'm starting a new program\n");
// // Exec(argv[1], argv + 1);
// } else {
// TracePrintf(0, "Fork2: I'm parent: %i\n", GetPid());
// }
// // Won't work if uncomment this!!
// if(Fork() == 0) {
// TracePrintf(0, "Fork3: I'm child: %i\n", GetPid());
// TracePrintf(0, "I'm starting a new program\n");
// // Exec(argv[1], argv + 1);
// } else {
// TracePrintf(0, "Fork3: I'm parent: %i\n", GetPid());
// }
// // Won't work if uncomment this!!
// if(Fork() == 0) {
// TracePrintf(0, "Fork4: I'm child: %i\n", GetPid());
// TracePrintf(0, "I'm starting a new program\n");
// // Exec(argv[1], argv + 1);
// } else {
// TracePrintf(0, "Fork4: I'm parent: %i\n", GetPid());
// }
TracePrintf(0, "process %i is about to exit\n", GetPid());
// TracePrintf(0, "2nd delay return value is %i for pid=%i\n", Delay(2), GetPid());
// Pause();
Exit(0);
}