使用ACE_Process创建子进程
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;}