By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,252 Members | 1,346 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,252 IT Pros & Developers. It's quick & easy.

How to end process using Java?

P: 1
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??
Oct 9 '09 #1
Share this Question
Share on Google+
4 Replies


myusernotyours
100+
P: 188
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
Expand|Select|Wrap|Line Numbers
  1. Runtime.getRuntime().exec("taskkill /IM myprocess.exe");
  2.  
Regards,

Alex.
Oct 9 '09 #2

P: 1
You can kill the process from task manager using Java

Expand|Select|Wrap|Line Numbers
  1. Runtime.getRuntime().exec("taskkill/F/IM processName.exe");
you can download the jar file to kill the process of task manager and you can see the java code for this task.

http://swatantrapage.blogspot.in/201...from-task.html
Jul 21 '15 #3

Kara Hewett
P: 27
You can also use Task Scheduler on a Windows Server and kill any java program which is running on that server.
Jun 15 '16 #4

P: 18
Expand|Select|Wrap|Line Numbers
  1. public class ProcessDemo  
  2.     public static void main(String[] args)  
  3.     { 
  4.         try 
  5.         { 
  6.  
  7.             // create a new process 
  8.             System.out.println("Creating Process"); 
  9.  
  10.             ProcessBuilder builder = new ProcessBuilder("notepad.exe"); 
  11.             Process pro = builder.start(); 
  12.  
  13.             // wait 10 seconds 
  14.             System.out.println("Waiting"); 
  15.             Thread.sleep(10000); 
  16.  
  17.             // kill the process 
  18.             pro.destroy(); 
  19.             System.out.println("Process destroyed"); 
  20.  
  21.         }  
  22.             catch (Exception ex)  
  23.         { 
  24.             ex.printStackTrace(); 
  25.         } 
  26.     } 
  27. }
Output:

Creating Process
Waiting
Process destroyed
1 Week Ago #5

Post your reply

Sign in to post your reply or Sign up for a free account.