summaryrefslogtreecommitdiffstats
path: root/base/process_util_posix.cc
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-28 01:37:23 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-28 01:37:23 +0000
commit140a7cd1d47292be7c5872c6019c1ab09af774e3 (patch)
tree5210806d7de816fa0025952e20bf6396b1c0d9fb /base/process_util_posix.cc
parenta7c2ff748541a96df53995216dc2a7c1209dca48 (diff)
downloadchromium_src-140a7cd1d47292be7c5872c6019c1ab09af774e3.zip
chromium_src-140a7cd1d47292be7c5872c6019c1ab09af774e3.tar.gz
chromium_src-140a7cd1d47292be7c5872c6019c1ab09af774e3.tar.bz2
POSIX: don't spawn zombies.
http://codereview.chromium.org/93147 BUG=9401 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14705 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_posix.cc')
-rw-r--r--base/process_util_posix.cc33
1 files changed, 23 insertions, 10 deletions
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index 2e3fd55..efe7442 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -56,23 +56,25 @@ ProcessId GetProcId(ProcessHandle process) {
// entry structure. Ignores specified exit_code; posix can't force that.
// Returns true if this is successful, false otherwise.
bool KillProcess(ProcessHandle process_id, int exit_code, bool wait) {
- bool result = false;
+ bool result = kill(process_id, SIGTERM) == 0;
- int status = kill(process_id, SIGTERM);
- if (!status && wait) {
+ if (result && 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;
+ int pid = waitpid(process_id, NULL, WNOHANG);
+ if (pid == process_id)
break;
- }
+
sleep(1);
}
+
+ result = kill(process_id, SIGKILL) == 0;
}
+
if (!result)
DLOG(ERROR) << "Unable to terminate process.";
+
return result;
}
@@ -141,13 +143,24 @@ void RaiseProcessToHighPriority() {
// setpriority() or sched_getscheduler, but these all require extra rights.
}
-bool DidProcessCrash(ProcessHandle handle) {
+bool DidProcessCrash(bool* child_exited, ProcessHandle handle) {
int status;
- if (waitpid(handle, &status, WNOHANG)) {
- // I feel like dancing!
+ const int result = waitpid(handle, &status, WNOHANG);
+ if (result == -1) {
+ LOG(ERROR) << "waitpid failed pid:" << handle << " errno:" << errno;
+ if (child_exited)
+ *child_exited = false;
+ return false;
+ } else if (result == 0) {
+ // the child hasn't exited yet.
+ if (child_exited)
+ *child_exited = false;
return false;
}
+ if (child_exited)
+ *child_exited = true;
+
if (WIFSIGNALED(status)) {
switch(WTERMSIG(status)) {
case SIGSEGV: