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

Unified Diff: base/process_util_posix.cc

Issue 3423012: Cleanup orphaned testserver processes on posix. (Closed)
Patch Set: CR feedback. Created 10 years, 3 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') | chrome/test/test_launcher/out_of_proc_test_runner.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 d6171b12ee09e218d3f86de813e4da209694a5e7..31a8e9db7a6664adafca582db4a2cd3f5455869a 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -195,6 +195,13 @@ bool KillProcess(ProcessHandle process_id, int exit_code, bool wait) {
return result;
}
+bool KillProcessGroup(ProcessHandle process_group_id) {
+ bool result = kill(-1 * process_group_id, SIGKILL) == 0;
+ if (!result)
+ PLOG(ERROR) << "Unable to terminate process group " << process_group_id;
+ return result;
+}
+
// A class to handle auto-closing of DIR*'s.
class ScopedDIRClose {
public:
@@ -420,12 +427,13 @@ char** AlterEnvironment(const environment_vector& changes,
return ret;
}
-bool LaunchApp(
+bool LaunchAppImpl(
const std::vector<std::string>& argv,
const environment_vector& env_changes,
const file_handle_mapping_vector& fds_to_remap,
bool wait,
- ProcessHandle* process_handle) {
+ ProcessHandle* process_handle,
+ bool start_new_process_group) {
pid_t pid;
InjectiveMultimap fd_shuffle1, fd_shuffle2;
fd_shuffle1.reserve(fds_to_remap.size());
@@ -439,6 +447,13 @@ bool LaunchApp(
if (pid == 0) {
// Child process
+
+ if (start_new_process_group) {
+ // Instead of inheriting the process group ID of the parent, the child
+ // starts off a new process group with pgid equal to its process ID.
+ if (setpgid(0, 0) < 0)
+ return false;
+ }
#if defined(OS_MACOSX)
RestoreDefaultExceptionHandler();
#endif
@@ -498,6 +513,26 @@ bool LaunchApp(
return true;
}
+bool LaunchApp(
+ const std::vector<std::string>& argv,
+ const environment_vector& env_changes,
+ const file_handle_mapping_vector& fds_to_remap,
+ bool wait,
+ ProcessHandle* process_handle) {
+ return LaunchAppImpl(argv, env_changes, fds_to_remap,
+ wait, process_handle, false);
+}
+
+bool LaunchAppInNewProcessGroup(
+ const std::vector<std::string>& argv,
+ const environment_vector& env_changes,
+ const file_handle_mapping_vector& fds_to_remap,
+ bool wait,
+ ProcessHandle* process_handle) {
+ return LaunchAppImpl(argv, env_changes, fds_to_remap, wait,
+ process_handle, true);
+}
+
bool LaunchApp(const std::vector<std::string>& argv,
const file_handle_mapping_vector& fds_to_remap,
bool wait, ProcessHandle* process_handle) {
« no previous file with comments | « base/process_util.h ('k') | chrome/test/test_launcher/out_of_proc_test_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698