diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-22 01:15:47 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-22 01:15:47 +0000 |
commit | fb7f9bef3ceecd5a3efb9252410f6850320462b8 (patch) | |
tree | 95cefb13965daa20689cebec67e48352be1ccfbf /base/process_util_linux.cc | |
parent | 0cbd643274f17abca0efaa82036ac8ccbc695be3 (diff) | |
download | chromium_src-fb7f9bef3ceecd5a3efb9252410f6850320462b8.zip chromium_src-fb7f9bef3ceecd5a3efb9252410f6850320462b8.tar.gz chromium_src-fb7f9bef3ceecd5a3efb9252410f6850320462b8.tar.bz2 |
Added linux process utilities and tests.
Review URL: http://codereview.chromium.org/7202
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3715 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_linux.cc')
-rw-r--r-- | base/process_util_linux.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc index e5bc5db..f53ba3b 100644 --- a/base/process_util_linux.cc +++ b/base/process_util_linux.cc @@ -5,6 +5,8 @@ #include "base/process_util.h" #include <string> +#include <sys/types.h> +#include <sys/wait.h> #include "base/file_util.h" #include "base/logging.h" @@ -22,6 +24,50 @@ enum ParsingState { namespace process_util { +bool LaunchApp(const std::vector<std::string>& argv, + bool wait, ProcessHandle* process_handle) { + bool retval = true; + + char* argv_copy[argv.size() + 1]; + for (size_t i = 0; i < argv.size(); i++) { + argv_copy[i] = new char[argv[i].size() + 1]; + strcpy(argv_copy[i], argv[i].c_str()); + } + argv_copy[argv.size()] = NULL; + + int pid = vfork(); + if (pid == 0) { + execv(argv_copy[0], argv_copy); + } else if (pid < 0) { + retval = false; + } else { + if (wait) + waitpid(pid, 0, 0); + + if(process_handle) + *process_handle = pid; + } + + for (size_t i = 0; i < argv.size(); i++) + delete[] argv_copy[i]; + + return retval; +} + +bool LaunchApp(const CommandLine& cl, + bool wait, bool start_hidden, ProcessHandle* process_handle) { + return LaunchApp(cl.argv(), wait, process_handle); +} + +bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) { + int status; + waitpid(handle, &status, 0); + return WIFEXITED(status); +} + +/////////////////////////////////////////////////////////////////////////////// +//// ProcessMetrics + // To have /proc/self/io file you must enable CONFIG_TASK_IO_ACCOUNTING // in your kernel configuration. bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) { |