| 1 |
ab11 |
1.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 A (1, 1); |
| 18 |
|
|
|
| 19 |
|
|
print ("A", A.process_id ()); |
| 20 |
|
|
if (A.is_child ()) { |
| 21 |
|
|
sleep (120); |
| 22 |
|
|
return 0x8; |
| 23 |
|
|
} |
| 24 |
|
|
sleep (30); |
| 25 |
|
|
return 0; |
| 26 |
|
|
} |
| 27 |
|
|
|