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
| #include <stdio.h>
| #include <unistd.h>
| #include <string.h>
| #include <errno.h>
|
| int main(int argc, char **argv)
| {
| pid_t pid;
|
| printf("Parent process PID[%d] start running...\n", getpid() );
|
| pid = fork();
| if(pid < 0)
| {
| printf("fork() create child process failure: %s\n", strerror(errno));
| return -1;
| }
| else if( pid == 0 )
| {
| printf("Child process PID[%d] start running, my parent PID is [%d]\n", getpid(), getppid());
| return 0;
| }
| else // if( pid > 0 )
| {
| printf("Parent process PID[%d] continue running, and child process PID is [%d]\n", getpid(), pid);
| return 0;
| }
| }
|
|