这几天来发表些疑难问题
以下是两个简单的fork程序,请问为什么结果不一样,本来理解为缓冲的问题,但....1 #include "stdio.h"
2 #include "stdlib.h"
3 #include "unistd.h"
4 #include "pthread.h"
5 #include "fcntl.h"
6 main()
7 {
8 pid_t pid;
9 printf(" *******");//here
10 pid=fork();
11 if(!pid)
12 {
13 printf("in child\n");
14 }
15 else if(pid >0)
16 {
17 sleep(20);
18 printf("hello\n");
19 }
20
21 }
1 #include "stdio.h"
2 #include "stdlib.h"
3 #include "unistd.h"
4 #include "pthread.h"
5 #include "fcntl.h"
6 main()
7 {
8 pid_t pid;
9 printf(" *******\n");//here
10 pid=fork();
11 if(!pid)
12 {
13 printf("in child\n");
14 }
15 else if(pid >0)
16 {
17 sleep(20);
18 printf("hello\n");
19 }
20
21 }