Ticket #131: fork.c
File fork.c, 515 bytes (added by , 18 years ago) |
---|
Line | |
---|---|
1 | #include <stdio.h> |
2 | #include <unistd.h> |
3 | |
4 | #define BSS_SIZE_MB 128 |
5 | |
6 | char buf[BSS_SIZE_MB*1024*1024]; |
7 | |
8 | int main() |
9 | { |
10 | pid_t pid; |
11 | |
12 | printf("Will do fork() rigth now\n"); |
13 | pid= fork(); |
14 | if( pid < 0 ) |
15 | { |
16 | printf("fork() failed\n"); |
17 | return 1; |
18 | } |
19 | if( pid == 0 ) |
20 | { |
21 | /* Child */ |
22 | printf("fork(): I'm child\n"); |
23 | } else |
24 | { |
25 | /* Child */ |
26 | printf("fork(): child pid= %d\n", pid); |
27 | waitpid(pid); |
28 | } |
29 | return 0; |
30 | } |