- 论坛徽章:
- 0
|
- #include<stdio.h>
- #include<stdlib.h>
- #include<signal.h>
- #include<unistd.h>
- void sig_op(int v)
- {
- printf("process %d is over\n",getpid());
- }
- int main()
- {
- pid_t pid;
- signal(SIGINT,sig_op);
- if( fork() == 0)
- {
- sleep(100);
- printf("child is over%d \n",getpid());
- }
- else
- { sleep(100);
- printf("parent is over%d \n",getpid());
- }
- }
复制代码 在上述代码中当执行之后我马上按下ctrl+c 会马上输出下面结果
^Cprocess 2999 is over
process 2998 is over
child is over2999
parent is over2998
sleep()函数是可重入函数,当我运行程序之后马上按ctrl+c 不是应该等一段时间才会输出
child is over2999
parent is over2998
吗???
求大神给予点拨!!!!!!!!!!!!!!!!!!! |
|