|
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <stdio.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <signal.h>
- #define MAIL "/var/spool/mail/xxx"
- #define SLEEP_TIME 10
- int
- main(void)
- {
- pid_t child;
- if( (child = fork()) == -1){
- printf("Fork Error: %s\n", strerror(errno));
- exit(1);
- }
- else if(child > 0)
- while(1);
- if(kill(getppid(), SIGTERM) == -1){
- printf("Kill Parent Error: %s\n", strerror(errno));
- exit(1);
- }
- {
- int mailfd;
- while(1){
- if((mailfd = open(MAIL, O_RDONLY)) != -1){
- fprintf(stderr, "%s","\007");
- close(mailfd);
- }
- sleep(SLEEP_TIME);
- }
- }
- }
复制代码
这是网上找来的代码,一直运行有问题,执行起来是Terminated!
大家帮忙运行一下,谢谢! |
|