forked from cksystemsteaching/selfie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fork.c
64 lines (56 loc) · 1.24 KB
/
fork.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
// libcstar procedures for printing
void init_library();
void print(uint64_t *s);
void print_character(uint64_t c);
void print_string(uint64_t *s);
void print_integer(uint64_t n);
void print_hexadecimal(uint64_t n, uint64_t a);
void print_octal(uint64_t n, uint64_t a);
void print_binary(uint64_t n, uint64_t a);
void println();
uint64_t *foo;
uint64_t main()
{
uint64_t pid;
uint64_t pid2;
uint64_t i;
uint64_t* status;
// initialize selfie's libcstar library
init_library();
pid = fork();
if (pid != 0)
{
// parent
wait(status);
print("Parent PID : ");
print_integer(pid);
println();
pid2 = fork();
if (pid2 != 0)
{
// parent
wait(status);
print("Parent 2 PID : ");
print_integer(pid2);
println();
}
else
{
// child
print("Child 2 PID : ");
print_integer(pid2);
println();
}
}else{
// child
print("Child PID : ");
print_integer(pid);
println();
}
foo = "Hello World! ";
while (*foo != 0)
{
write(1, foo, 8);
foo = foo + 1;
}
}