4 #include <msp/core/systemerror.h>
5 #include <msp/fs/dir.h>
6 #include <msp/io/console.h>
9 #include "process_private.h"
20 void Process::platform_get_self_info(Private &priv)
22 priv.info.pid = getpid();
25 void Process::execute(const string &command, bool path_search, const Arguments &args)
32 throw system_error("fork");
37 vector<const char *> argv(args.size()+2);
38 argv[0] = command.c_str();
39 for(unsigned i=0; i<args.size(); ++i)
40 argv[i+1] = args[i].c_str();
41 argv[args.size()+1] = nullptr;
45 // dup2 clears O_CLOEXEC
47 IO::cin.redirect(*cin);
49 IO::cout.redirect(*cout);
51 IO::cerr.redirect(*cerr);
58 execvp(command.c_str(), const_cast<char *const *>(&argv[0]));
60 execv(command.c_str(), const_cast<char *const *>(&argv[0]));
73 bool Process::wait(bool block)
76 throw invalid_state("not running");
79 int pid = waitpid(priv->info.pid, &status, (block ? 0 : WNOHANG));
81 throw system_error("waitpid");
88 exit_code = WEXITSTATUS(status);
89 else if(WIFSIGNALED(status))
90 exit_code = 0x100|WTERMSIG(status);
96 void Process::terminate()
98 ::kill(priv->info.pid, SIGTERM);
103 ::kill(priv->info.pid, SIGKILL);
106 void Process::interrupt()
108 ::kill(priv->info.pid, SIGINT);
112 Process::Private::Private()