Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1063138
  • 博文数量: 284
  • 博客积分: 8223
  • 博客等级: 中将
  • 技术积分: 3188
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-01 13:26
文章分类

全部博文(284)

文章存档

2012年(18)

2011年(33)

2010年(83)

2009年(147)

2008年(3)

分类: C/C++

2009-06-09 09:01:49

#include
#include
#include
#include
#include
#include
#include
#include
#include
void pr()
{
  printf("just test this is exit\n");
}
int main(int argc, char **argv[])
{
  int pid;
  int count=0;
  pid = fork();
  if(pid < 0) printf("error fork\n");
  else if(pid == 0){
    while(1)
    {
      printf("now  count = %d\n", count++);
      sleep(1);
    }
  }
  else { 
     time_t now_t;
     time_t now_s;
     struct tm now_tm;
     now_s = now_t = time(NULL);
     printf("now parent is waiting\n");
     while ((now_t - now_s)< 10)
     {
       now_t = time(NULL);
     }
     kill(pid, SIGKILL);
    atexit(pr);
     printf("now end\n");
     exit(0);
  }
}
 
阅读(541) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~