void ShellWorker::perform() { output_.clear(); child_ = vfork(); switch (child_) { case -1: // error perror("vfork"); finish(false); break; case 0: // in child setupChild(); break; default: // in parent setupParent(); break; } }
int Process::start(const std::string& exe, const ArgumentList& args, const Environment& env, const std::string& workdir) { #if !defined(NDEBUG) //::fprintf(stderr, "proc[%d] start(exe=%s, args=[...], workdir=%s)\n", getpid(), exe.c_str(), workdir.c_str()); for (int i = 3; i < 32; ++i) if (!(fcntl(i, F_GETFD) & FD_CLOEXEC)) fprintf(stderr, "Process: fd %d still open\n", i); #endif switch (pid_ = vfork()) { case -1: // error fprintf(stderr, "Process: error starting process: %s\n", strerror(errno)); return -1; case 0: // child setupChild(exe, args, env, workdir); break; default: // parent setupParent(); break; } return 0; }