forked from remzi-arpacidusseau/ostep-code
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathorphan.c
More file actions
26 lines (25 loc) · 698 Bytes
/
Copy pathorphan.c
File metadata and controls
26 lines (25 loc) · 698 Bytes
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
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
printf("hello world (pid:%d)\n", (int) getpid());
pid_t pid;
pid = fork();
if (pid < 0)
printf("error occurred!\n");
else if (pid == 0) {
printf("I'm a child (pid:%d) of (pid:%d)\n",
(int) getpid(), (int) getppid());
sleep(60);
printf("I'm a orphan (pid:%d), adopted by (pid:%d)\n",
(int) getpid(), (int) getppid());
exit(0); //(1)
} else {
sleep(20);
printf("The father (pid:%d) says goodbye to the child (pid:%d)\n",
(int) getpid(), pid);
}
}