IDEA-131748 Stop debug session kills all processes - added a registry flag to disable...
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Fri, 6 May 2016 10:11:04 +0000 (13:11 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Fri, 6 May 2016 10:11:54 +0000 (13:11 +0300)
platform/platform-impl/src/com/intellij/execution/process/OSProcessUtil.java
platform/util/resources/misc/registry.properties
platform/util/src/com/intellij/execution/process/WinProcessManager.java

index 1ab41a7fa0e68ec84db2735c819647b037e4dc19..4c24b93e0d6a74b316f655b483bb9f0c9e9020eb 100644 (file)
@@ -19,6 +19,7 @@ package com.intellij.execution.process;
 import com.intellij.execution.process.impl.ProcessListUtil;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.SystemInfo;
+import com.intellij.openapi.util.registry.Registry;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jvnet.winp.WinProcess;
@@ -27,17 +28,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-/******************************************************************************
- * Copyright (C) 2013  Fabio Zadrozny
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     Fabio Zadrozny <fabiofz@gmail.com> - initial API and implementation
- ******************************************************************************/
 public class OSProcessUtil {
   private static final Logger LOG = Logger.getInstance(OSProcessUtil.class);
 
@@ -49,8 +39,12 @@ public class OSProcessUtil {
   public static boolean killProcessTree(@NotNull Process process) {
     if (SystemInfo.isWindows) {
       try {
-        WinProcess winProcess = createWinProcess(process);
-        winProcess.killRecursively();
+        if (Registry.is("disable.winp")) {
+          WinProcessManager.kill(process, true);
+        }
+        else {
+          createWinProcess(process).killRecursively();
+        }
         return true;
       }
       catch (Throwable e) {
@@ -66,8 +60,12 @@ public class OSProcessUtil {
   public static void killProcess(@NotNull Process process) {
     if (SystemInfo.isWindows) {
       try {
-        WinProcess winProcess = createWinProcess(process);
-        winProcess.kill();
+        if (Registry.is("disable.winp")) {
+          WinProcessManager.kill(process, false);
+        }
+        else {
+          createWinProcess(process).kill();
+        }
       }
       catch (Throwable e) {
         LOG.info("Cannot kill process", e);
@@ -77,11 +75,16 @@ public class OSProcessUtil {
       UnixProcessManager.sendSignal(UnixProcessManager.getProcessPid(process), UnixProcessManager.SIGKILL);
     }
   }
-  
+
   public static int getProcessID(@NotNull Process process) {
     if (SystemInfo.isWindows) {
       try {
-        return createWinProcess(process).getPid();
+        if (Registry.is("disable.winp")) {
+          WinProcessManager.getProcessPid(process);
+        }
+        else {
+          return createWinProcess(process).getPid();
+        }
       }
       catch (Throwable e) {
         LOG.info("Cannot get process id", e);
index 5d57e3d0e7710ba95bd9a7d307fecffa30f7d89d..50f50b06f13a7f4770207bebce36f663e78aefec 100644 (file)
@@ -499,6 +499,7 @@ editor.injected.highlighting.enabled.description=Disables injected fragments hig
 run.processes.with.pty=false
 kill.windows.processes.softly=false
 output.reader.blocking.mode=false
+disable.winp=false
 
 ide.certificate.manager=true
 
index 5b7ef5e100d169b8182d932b8448d1865f07e7b0..47f953e9b8a73d76cc83e72a4330c408837ea760 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -20,6 +20,8 @@ import com.sun.jna.Pointer;
 import com.sun.jna.platform.win32.Kernel32;
 import com.sun.jna.platform.win32.WinNT;
 
+import java.io.IOException;
+
 /**
  * @author Alexey.Ushakov
  */
@@ -49,4 +51,14 @@ public class WinProcessManager {
       throw new IllegalStateException("Unknown Process implementation");
     }
   }
+
+  /**
+   * Force kill a process (tree)
+   * @param process Windows process
+   * @param tree true to also kill all subprocesses
+   */
+  public static void kill(Process process, boolean tree) throws IOException, InterruptedException {
+    int pid = getProcessPid(process);
+    Runtime.getRuntime().exec("taskkill /PID " + pid + (tree ? " /t" : "") + " /f").waitFor();
+  }
 }