`
sogo6
  • 浏览: 110819 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

使用ACE_Process创建子进程

    博客分类:
  • ACE
 
阅读更多
int createProcess()
{
    int retCode = ACE::daemonize();
    std::cout << "retCode = " << retCode << ", lasterror = " << ACE_OS::last_error() << std::endl;

    std::string command = "ping -t 10.71.211.153";
    ACE_Process_Options startOption;
    ACE_Process startProcess;

    startOption.command_line("%s", command.c_str());
    startOption.handle_inheritence(FALSE);

    // 设置一下libpath
    /*
    const int ENVNUM = 1;  //需要设置的环境变量数为2
    ACE_TCHAR *pEnvString[ENVNUM+1] = {0}; //最后一个指向0
    std::string libPath = "";
#ifdef WIN32
    libPath = ::getenv("PATH");
#else
    libPath = ACE_OS::getenv("LD_LIBRARY_PATH");
#endif

    procOption.setenv();
    */

#ifdef WIN32
    ACE_HANDLE fd = ACE_OS::open("nul", O_RDWR);
#else
    int fd = ACE_OS::open("/dev/null", O_RDWR);
#endif
    //startOption.set_handles(fd, fd, fd);
    pid_t pid = startProcess.spawn(startOption);
    ACE_OS::close(fd);

    startProcess.wait();

    return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics