4 #include <msp/core/systemerror.h>
5 #include <msp/fs/dir.h>
6 #include <msp/io/console.h>
8 #include "process_private.h"
17 void Process::platform_get_self_info(Private &priv)
19 priv.info.pid = getpid();
22 void Process::execute(const string &command, bool path_search, const Arguments &args)
29 throw system_error("fork");
34 vector<const char *> argv(args.size()+2);
35 argv[0] = command.c_str();
36 for(unsigned i=0; i<args.size(); ++i)
37 argv[i+1] = args[i].c_str();
38 argv[args.size()+1] = 0;
42 // dup2 clears O_CLOEXEC
44 IO::cin.redirect(*cin);
46 IO::cout.redirect(*cout);
48 IO::cerr.redirect(*cerr);
55 execvp(command.c_str(), const_cast<char *const *>(&argv[0]));
57 execv(command.c_str(), const_cast<char *const *>(&argv[0]));
70 bool Process::wait(bool block)
73 throw logic_error("not running");
76 int pid = waitpid(priv->info.pid, &status, (block ? 0 : WNOHANG));
78 throw system_error("waitpid");
85 exit_code = WEXITSTATUS(status);
86 else if(WIFSIGNALED(status))
87 exit_code = 0x100|WTERMSIG(status);
93 void Process::terminate()
95 ::kill(priv->info.pid, SIGTERM);
100 ::kill(priv->info.pid, SIGKILL);
103 void Process::interrupt()
105 ::kill(priv->info.pid, SIGINT);
109 Process::Private::Private()