LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 756|回复: 1

帮忙运行一个程序看看结果

[复制链接]
发表于 2007-7-2 23:09:30 | 显示全部楼层 |阅读模式

  1. #include <unistd.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <stdio.h>
  5. #include <errno.h>
  6. #include <fcntl.h>
  7. #include <signal.h>

  8. #define MAIL "/var/spool/mail/xxx"

  9. #define SLEEP_TIME    10

  10. int
  11. main(void)
  12. {
  13.     pid_t    child;

  14.     if( (child = fork()) == -1){
  15.         printf("Fork Error: %s\n", strerror(errno));
  16.         exit(1);
  17.     }
  18.     else if(child > 0)
  19.         while(1);

  20.     if(kill(getppid(), SIGTERM) == -1){
  21.         printf("Kill Parent Error: %s\n", strerror(errno));
  22.         exit(1);
  23.     }
  24.     {
  25.         int mailfd;

  26.         while(1){
  27.             if((mailfd = open(MAIL, O_RDONLY)) != -1){
  28.                 fprintf(stderr, "%s","\007");
  29.                 close(mailfd);
  30.             }
  31.             sleep(SLEEP_TIME);
  32.         }
  33.     }
  34. }
复制代码



这是网上找来的代码,一直运行有问题,执行起来是Terminated!

大家帮忙运行一下,谢谢!
发表于 2007-7-3 09:06:25 | 显示全部楼层
这段代码好烂
不过执行了是应该显示Terminated阿
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表