,linux子进程与信号量机制的有关问题,为什么子进程中有raise函数,raise函数之前的printf也不执行了呢,不应该是按顺序执行的么
求助,linux子进程与信号量机制的问题,为什么子进程中有raise函数,raise函数之前的printf也不执行了呢,不应该是按顺序执行的么
1 #include<stdio.h>
2 #include<sys/wait.h>
3 #include<sys/types.h>
4 #include<unistd.h>
5 #include<errno.h>
6 #include<signal.h>
7 int main()
8 {
9 pid_t pid=fork();
10 int ret;
11 if(pid<0)
12 perror("fork");
13 if(pid==0)
14 {
15 puts("in chile process");
16 printf("111111111111");
17 printf("222222222222");
18 printf("333333333333");
19 raise(SIGSTOP);
20 // puts("test");
21 return(0);
22 }
23 else
24 {
25 printf("create pid=%d",pid);
26 int i;
27
28 sleep(1);
29 if(waitpid(pid,NULL,WNOHANG)==0)
30 {
31 if(ret=kill(pid,SIGKILL)==0)
32 printf("kill's return is:%d,pid =%d\n",ret,p id);
33 else
34 perror("kill failed");
35
36 }
37 }
38 return 0;
39 }
------解决思路----------------------
the reason you can't see the printf output is because those characters are in the stdout buffer
printf("111111111111\n");
printf("222222222222\n");
printf("333333333333\n");
stdout is line buffered if the process is associated with console. By appending a newline '\n' at the end of the char string, sttdout buffer will be flushed to the console.
you could also do:
printf("111111111111");
printf("222222222222");
printf("333333333333");
printf("\n");
that might give you a better view on the effect of '\n';
------解决思路----------------------
可以刷新下缓存看看
1 #include<stdio.h>
2 #include<sys/wait.h>
3 #include<sys/types.h>
4 #include<unistd.h>
5 #include<errno.h>
6 #include<signal.h>
7 int main()
8 {
9 pid_t pid=fork();
10 int ret;
11 if(pid<0)
12 perror("fork");
13 if(pid==0)
14 {
15 puts("in chile process");
16 printf("111111111111");
17 printf("222222222222");
18 printf("333333333333");
19 raise(SIGSTOP);
20 // puts("test");
21 return(0);
22 }
23 else
24 {
25 printf("create pid=%d",pid);
26 int i;
27
28 sleep(1);
29 if(waitpid(pid,NULL,WNOHANG)==0)
30 {
31 if(ret=kill(pid,SIGKILL)==0)
32 printf("kill's return is:%d,pid =%d\n",ret,p id);
33 else
34 perror("kill failed");
35
36 }
37 }
38 return 0;
39 }
------解决思路----------------------
the reason you can't see the printf output is because those characters are in the stdout buffer
printf("111111111111\n");
printf("222222222222\n");
printf("333333333333\n");
stdout is line buffered if the process is associated with console. By appending a newline '\n' at the end of the char string, sttdout buffer will be flushed to the console.
you could also do:
printf("111111111111");
printf("222222222222");
printf("333333333333");
printf("\n");
that might give you a better view on the effect of '\n';
------解决思路----------------------
可以刷新下缓存看看