Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5699923
  • 博文数量: 675
  • 博客积分: 20301
  • 博客等级: 上将
  • 技术积分: 7671
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-31 16:15
文章分类

全部博文(675)

文章存档

2012年(1)

2011年(20)

2010年(14)

2009年(63)

2008年(118)

2007年(141)

2006年(318)

分类: C/C++

2007-11-19 19:00:49

snort中的守护进程创建函数:
void GoDaemon(void)
{
    pid_t fs;

    printf("Initializing daemon mode\n");

    if(getppid() != 1)
    {
        fs = fork();

        if(fs > 0)
            exit(0);                /* parent */

        if(fs < 0)
        {
            perror("fork");
            exit(1);
        }
        setsid();
    }
  chdir("/");
    /* redirect stdin/stdout/stderr to /dev/null */
    close(0);
    close(1);
    close(2);

#ifdef DEBUG
    open("/tmp/snort.debug", O_CREAT | O_RDWR);
#else
    open("/dev/null", O_RDWR);
#endif

    dup(0);
    dup(0);

    return;
}
关于守护进程的细节,可以参考:
http://blog.chinaunix.net/u/12592/showart.php?id=209697
或者是APUE第13章守护进程
阅读(1219) | 评论(0) | 转发(0) |
0

上一篇:chroot()使用

下一篇:getopt函数的使用

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