Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3391)

Unified Diff: base/process_util_posix.cc

Issue 93147: POSIX: don't spawn zombies. (Closed)
Patch Set: ... Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process_util.h ('k') | base/process_util_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_util_posix.cc
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index 562b8e908f999f0550ede140952ab6f3a7cf9574..489c4cd705071ad4b6cbf5df33e395cc4a009605 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -55,23 +55,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 = false;
}
+
if (!result)
DLOG(ERROR) << "Unable to terminate process.";
+
return result;
}
@@ -140,13 +142,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:
« no previous file with comments | « base/process_util.h ('k') | base/process_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698