Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1408927
  • 博文数量: 430
  • 博客积分: 9995
  • 博客等级: 中将
  • 技术积分: 4388
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-24 18:04
文章存档

2013年(1)

2008年(2)

2007年(14)

2006年(413)

分类:

2006-07-14 09:21:31

#include
#include
#include
#include
#include
#include
#include
#include
void goback(void)
{
        int i=0;
        pid_t pid;
        chdir("/");
        pid=fork();
        if (pid<0) {
                perror("fork");
                exit(1);
        } else if (pid>0)
                exit(0);
        setsid();
        syslog(LOG_INFO|LOG_LOCAL2,"%s,%d","The deamon is started!!!\n",getpid());
}
int main(void)
{
        int ret;
        int fd;
        goback();
        fd=open("/dev/console",O_RDWR|O_NOCTTY);
        if(fd<0) {
                perror("open console");
                exit(1);
        }
        ret=write(fd,"\007\007\007\007",strlen("\007\007\007\007"));
        if(ret<0) {
                perror("write");
                exit(1);
        }
        while(1)
                sleep(1);
        return 0;
}
阅读(1652) | 评论(0) | 转发(0) |
0

上一篇:守护进程的创建

下一篇:UNIX中的精灵进程

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