I am able to fetch all the processes which are running in Windows task Manager. Now I want to end a particular process from those processes. Is it possible in Java, or do i need to write some native code??
How to end process using Java?
Collapse
X
-
How are you fetching the list in of processes in the first place? Through native code?
I assume you only want to do it on windows.
You can use
Regards,Code:Runtime.getRuntime().exec("taskkill /IM myprocess.exe");
Alex. -
You can kill the process from task manager using Java
you can download the jar file to kill the process of task manager and you can see the java code for this task.Code:Runtime.getRuntime().exec("taskkill/F/IM processName.exe");
Comment
-
You can also use Task Scheduler on a Windows Server and kill any java program which is running on that server.Comment
-
Output:Code:public class ProcessDemo public static void main(String[] args) { try { // create a new process System.out.println("Creating Process"); ProcessBuilder builder = new ProcessBuilder("notepad.exe"); Process pro = builder.start(); // wait 10 seconds System.out.println("Waiting"); Thread.sleep(10000); // kill the process pro.destroy(); System.out.println("Process destroyed"); } catch (Exception ex) { ex.printStackTrace(); } } }
Creating Process
Waiting
Process destroyedComment
Comment