diff options
author | dkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-05 19:53:30 +0000 |
---|---|---|
committer | dkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-05 19:53:30 +0000 |
commit | 8cf7cebdf712b188970a396be6918d6d6a222835 (patch) | |
tree | 14db9f00124e7a911f6fe08e9614cd2c110b63ce /base/process_util_posix.cc | |
parent | 786a5fafa65bf9735f7e5060e126303307bb73bc (diff) | |
download | chromium_src-8cf7cebdf712b188970a396be6918d6d6a222835.zip chromium_src-8cf7cebdf712b188970a396be6918d6d6a222835.tar.gz chromium_src-8cf7cebdf712b188970a396be6918d6d6a222835.tar.bz2 |
Move KillProcess from linux to posix so it can be used on the Mac.
This was originally part of http://codereview.chromium.org/16207
and is broken out here so I can get the small stuff out of the way.
Review URL: http://codereview.chromium.org/16498
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7554 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_posix.cc')
-rw-r--r-- | base/process_util_posix.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index 2cfa6f9..dee917d 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -4,6 +4,7 @@ #include "base/process_util.h" +#include <signal.h> #include <sys/resource.h> #include <sys/time.h> #include <sys/types.h> @@ -32,6 +33,30 @@ int GetProcId(ProcessHandle process) { return process; } +// Attempts to kill the process identified by the given process +// entry structure. Ignores specified exit_code; posix can't force that. +// Returns true if this is successful, false otherwise. +bool KillProcess(int process_id, int exit_code, bool wait) { + bool result = false; + + int status = kill(process_id, SIGTERM); + if (!status && wait) { + int tries = 60; + // The process may not end immediately due to pending I/O + while (tries-- > 0) { + int pid = waitpid(process_id, &status, WNOHANG); + if (pid == process_id) { + result = true; + break; + } + sleep(1); + } + } + if (!result) + DLOG(ERROR) << "Unable to terminate process."; + return result; +} + int GetMaxFilesOpenInProcess() { struct rlimit rlimit; if (getrlimit(RLIMIT_NOFILE, &rlimit) != 0) { |