Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30335
  • 博文数量: 9
  • 博客积分: 70
  • 博客等级: 民兵
  • 技术积分: 44
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-08 17:43
文章分类
文章存档

2014年(5)

2013年(1)

2012年(3)

我的朋友

分类: LINUX

2012-02-10 15:15:19

   都是自己写代码的粗心造成的,留个纪念!
 
 
 
 
 

#include
#include
#include
#include
int doit(int);
int main(void)
{
  while  (1){
  int reval =0;
  int pid;
  pid = fork();
  switch (pid){
    case -1 :
      printf("\nfork is error\n");
      break;
    case 0  :
      printf("\nin child process id %d\n",getpid());
      sleep(2);
      exit (1);   //  当时忘了终止 子进程! 所以悲剧了!!
      break;
   default :
      break;
  }
  printf("\n%d\n",reval);
  signal(SIGCHLD,doit);
  sleep(10);
  printf("\ntest\n");
 }
}
int doit(int sig){
  if (sig ==SIGCHLD)
  printf("\n---------doit---------\n");
  else  printf("\n!!!!!!!!!!!\n");
  return 0;
}
 
 
1:
 
2: 如果 子进程 处理时间极短 ,   父进程在没有 运行到 sleep ()的时候, 就接收了SIGCHILD 信号,
3:父进程 在运行sleep() 了,  接收到 SIGCHILD 信号!  sleep()中断!
 
不知道还没有其他的理解, 有错误的帮我 指出来!!谢谢! 
 
 
 
 
 
 
 
 
阅读(803) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:上班挤公交的那点破事!

给主人留下些什么吧!~~