小编chr*_*sMe的帖子

在Linux中创建守护进程

在Linux中我想添加一个无法停止的守护进程,它监视文件系统的变化.如果检测到任何更改,它应该将路径写入启动它的控制台加上换行符.

我已经有文件系统更改代码几乎准备好但我无法弄清楚如何创建一个守护进程.

我的代码来自:http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html

叉子后要做什么?

int main (int argc, char **argv) {

  pid_t pID = fork();
  if (pID == 0)  {              // child
          // Code only executed by child process    
      sIdentifier = "Child Process: ";
    }
    else if (pID < 0) {
        cerr << "Failed to fork" << endl;
        exit(1);
       // Throw exception
    }
    else                                   // parent
    {
      // Code only executed by parent process

      sIdentifier = "Parent Process:";
    }       

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c linux daemon

97
推荐指数
6
解决办法
18万
查看次数

标签 统计

c ×1

daemon ×1

linux ×1