taskkill command works with cmd but not working in java code to end process tree

179 views Asked by At

when I type taskkill /f /t /pid xxx in Command Prompt, my process tree ends correctly. However, the code block below written in Java ends all processes in my process tree except one of them. Could you help me?

String pid = getPidWithSomeWay();
ProcessBuilder pb1 = new ProcessBuilder("cmd.exe","/c","taskkill /f /t /pid " + pid);
Process p1 = pb1.start();

Also, I tried ending process tree implementation with ProcessHandle, but I am facing the same problem.

0

There are 0 answers