- 论坛徽章:
- 0
|
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void sig_alrm (int singo);
int main(int argc, char *argv[])
{
pid_t pid;
unsigned int unslept;
signal(SIGALRM, sig_alrm);
if( (pid = fork()) <0)
perror("fork error!\n");
else if(pid == 0)
{
sleep(3);
kill(getppid(), SIGALRM);
printf("child exit!\n");
exit(0);
}
else
{
unslept = sleep(10);
printf("parent awakened!\n");
printf("unslept time = %u\n", unslept);
}
return 0;
}
void sig_alrm (int singo)
{
signal(SIGALRM, SIG_DFL);
return ;
} /* ----- end of function sig_alrm ----- */
运行的结果是:
child exit!
parent awakened!
unslept time = 7
为什么父进程接受到了SIGALRM不立即终止呢?SIGALRM默认操作不是终止吗?
谢谢!
[ 本帖最后由 samuel1004 于 2007-4-14 18:26 编辑 ] |
|