关于父子进程和信号量的问题
#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
吗???
求大神给予点拨!!!!!!!!!!!!!!!!!!! 用户态的sleep函数被ctl + c终止,立即返回,这个貌似没问题吧。
用户态的sleep()makesthecallingthread sleep until seconds seconds have elapsed or a signal arrives which is not ignored
你是不是和内核中的msleep()搞混淆了,内核态的msleep才是UNINTERRUPTIBLE ? 回复 2# 镇水铁牛
谢谢了,我对函数的重入性理解错了。谢谢你了
页:
[1]