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

Side by Side Diff: runtime/bin/process_linux.cc

Issue 8506009: Avoid creating zombie processes by waiting for the terminated process. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/process_macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/process.h"
6
5 #include <errno.h> 7 #include <errno.h>
6 #include <fcntl.h> 8 #include <fcntl.h>
7 #include <signal.h> 9 #include <signal.h>
8 #include <stdio.h> 10 #include <stdio.h>
9 #include <stdlib.h> 11 #include <stdlib.h>
10 #include <string.h> 12 #include <string.h>
13 #include <sys/wait.h>
11 #include <unistd.h> 14 #include <unistd.h>
12 15
13 #include "bin/fdutils.h" 16 #include "bin/fdutils.h"
14 #include "bin/process.h"
15
16 17
17 class ProcessInfo { 18 class ProcessInfo {
18 public: 19 public:
19 ProcessInfo(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { } 20 ProcessInfo(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { }
20 21
21 pid_t pid() { return pid_; } 22 pid_t pid() { return pid_; }
22 intptr_t fd() { return fd_; } 23 intptr_t fd() { return fd_; }
23 ProcessInfo* next() { return next_; } 24 ProcessInfo* next() { return next_; }
24 void set_next(ProcessInfo* next) { next_ = next; } 25 void set_next(ProcessInfo* next) { next_ = next; }
25 26
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 ASSERT(process_signal == SIGCHLD); 88 ASSERT(process_signal == SIGCHLD);
88 struct sigaction act; 89 struct sigaction act;
89 bzero(&act, sizeof(act)); 90 bzero(&act, sizeof(act));
90 act.sa_handler = SIG_IGN; 91 act.sa_handler = SIG_IGN;
91 act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO; 92 act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
92 if (sigaction(SIGCHLD, &act, 0) != 0) { 93 if (sigaction(SIGCHLD, &act, 0) != 0) {
93 perror("Process start: disabling signal handler failed"); 94 perror("Process start: disabling signal handler failed");
94 } 95 }
95 ProcessInfo* process = LookupProcess(siginfo->si_pid); 96 ProcessInfo* process = LookupProcess(siginfo->si_pid);
96 if (process != NULL) { 97 if (process != NULL) {
98 int status = 0;
99 int wait_result = waitpid(siginfo->si_pid, &status, WNOHANG);
100 if (wait_result == -1 || wait_result == 0) {
101 perror("ExitHandler waitpid failed");
102 }
97 intptr_t message[2] = { siginfo->si_pid, siginfo->si_status }; 103 intptr_t message[2] = { siginfo->si_pid, siginfo->si_status };
98 intptr_t result = 104 intptr_t result =
99 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message)); 105 FDUtils::WriteToBlocking(process->fd(), &message, sizeof(message));
100 if (result != sizeof(message)) { 106 if (result != sizeof(message)) {
101 perror("ExitHandler notification failed"); 107 perror("ExitHandler notification failed");
102 } 108 }
103 close(process->fd()); 109 close(process->fd());
104 } 110 }
105 act.sa_handler = 0; 111 act.sa_handler = 0;
106 act.sa_sigaction = ExitHandler; 112 act.sa_sigaction = ExitHandler;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 if (result == -1) { 335 if (result == -1) {
330 return false; 336 return false;
331 } 337 }
332 return true; 338 return true;
333 } 339 }
334 340
335 341
336 void Process::Exit(intptr_t id) { 342 void Process::Exit(intptr_t id) {
337 RemoveProcess(id); 343 RemoveProcess(id);
338 } 344 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/process_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698