From fd134ec18f00723b20a0805e1ebfe28ba55ea08b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 16 Oct 2017 17:15:02 +0200 Subject: [PATCH] [util] opens UnixProcessManager.sendSignalToProcessTree(int, int) --- .../execution/process/UnixProcessManager.java | 65 ++++++++----------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/platform/util/src/com/intellij/execution/process/UnixProcessManager.java b/platform/util/src/com/intellij/execution/process/UnixProcessManager.java index e03d28911b46..7dfe149e56cf 100644 --- a/platform/util/src/com/intellij/execution/process/UnixProcessManager.java +++ b/platform/util/src/com/intellij/execution/process/UnixProcessManager.java @@ -1,18 +1,16 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2017 JetBrains s.r.o. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package com.intellij.execution.process; import com.intellij.openapi.diagnostic.Logger; @@ -84,27 +82,37 @@ public class UnixProcessManager { } } - public static boolean sendSigIntToProcessTree(Process process) { + public static boolean sendSigIntToProcessTree(@NotNull Process process) { return sendSignalToProcessTree(process, SIGINT); } - public static boolean sendSigKillToProcessTree(Process process) { + public static boolean sendSigKillToProcessTree(@NotNull Process process) { return sendSignalToProcessTree(process, SIGKILL); } - private static boolean doSendSignalToProcessTree(int process_pid, int signal) { + public static boolean sendSignalToProcessTree(@NotNull Process process, int signal) { + try { + return sendSignalToProcessTree(getProcessPid(process), signal); + } + catch (Exception e) { + LOG.warn("Error killing the process", e); + return false; + } + } + + public static boolean sendSignalToProcessTree(int processId, int signal) { checkCLib(); final int our_pid = C_LIB.getpid(); if (LOG.isDebugEnabled()) { - LOG.debug("Sending signal " + signal + " to process tree with root PID " + process_pid); + LOG.debug("Sending signal " + signal + " to process tree with root PID " + processId); } final Ref foundPid = new Ref(); final ProcessInfo processInfo = new ProcessInfo(); final List childrenPids = new ArrayList(); - findChildProcesses(our_pid, process_pid, foundPid, processInfo, childrenPids); + findChildProcesses(our_pid, processId, foundPid, processInfo, childrenPids); // result is true if signal was sent to at least one process final boolean result; @@ -125,23 +133,6 @@ public class UnixProcessManager { return result; } - /** - * Sends signal to every child process of a tree root process - * - * @param process tree root process - */ - public static boolean sendSignalToProcessTree(@NotNull Process process, int signal) { - try { - final int process_pid = getProcessPid(process); - return doSendSignalToProcessTree(process_pid, signal); - } - catch (Exception e) { - //If we fail somehow just return false - LOG.warn("Error killing the process", e); - return false; - } - } - private static void findChildProcesses(final int our_pid, final int process_pid, final Ref foundPid,