1 |
#include <iostream.h> |
2 |
#include <Fork.h> |
3 |
|
4 |
static void print (char* name, pid_t child) |
5 |
{ |
6 |
if (child) { |
7 |
cerr << "Parent " << getppid () << "; " |
8 |
<< name << ' ' << getpid () << "; Child " << child << ";\n"; |
9 |
} else if (0) { |
10 |
cerr << "Parent " << getppid () << "; " |
11 |
<< name << "'s child " << getpid () << ";\n"; |
12 |
} |
13 |
} |
14 |
|
15 |
int main (int ac, char** av) |
16 |
{ |
17 |
Fork::suicide_signal (SIGTERM); |
18 |
|
19 |
Fork a(0, 1); |
20 |
|
21 |
print ("a", a.process_id ()); |
22 |
|
23 |
if (a.is_child ()) { |
24 |
sleep (3000); |
25 |
} else if (a.is_parent ()) { |
26 |
Fork b (1, 1); |
27 |
print ("b", b.process_id ()); |
28 |
{ |
29 |
Fork c (b.is_parent (), 1); |
30 |
if (b.is_child ()) |
31 |
print ("cchild", c.process_id ()); |
32 |
else |
33 |
print ("cparent", c.process_id ()); |
34 |
if (c.is_child ()) { |
35 |
sleep (3000); |
36 |
return 0; |
37 |
} |
38 |
} |
39 |
if (b.is_child ()) { |
40 |
sleep (120); |
41 |
return 0x8; |
42 |
} |
43 |
} |
44 |
|
45 |
return 0; |
46 |
} |
47 |
|