473,382 Members | 1,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to end process using Java?

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
4 10821
myusernotyours
188 100+
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
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
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
Sherin
77 64KB
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
May 14 '20 #5

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

Similar topics

5
by: Seong Jin, Cho | last post by:
Hi. Is there a way to get an unbuffered InputStream from Process? I found out that java.lang.Win32Process and java.lang.UNIXProcess both wraps the stdout with java.io.BufferedInputStream, but...
4
by: Prince Kumar | last post by:
I joined a company recently and they have a java program which hangs (does nothing) after a while. This is no way consistent. It could succeed quite a few times and can fail a few other times....
3
by: jbenezech | last post by:
Hi All, I have a perl script which starts a java process using Win32::Process. Here is the code to start the java proces: Win32::Process::Create($ProcessObj, ...
0
by: ivanov.andrei | last post by:
Working with Windows 2003 Server. Here's the weird behavior I see. Suppose I want to launch a new process that takes me to some website, http://127.0.0.1/ Now suppose that this website uses Java...
0
by: jbenezech | last post by:
Hi all , I have a perl/java app running under Win32. The application consists of a perl service (Win32::Daemon) and of java classes. The perl service calls every xx hours java classes to perform...
1
by: henrymania | last post by:
Am writing a code for database backup....by backupservlet is as given below i get the following exception
1
by: Evan | last post by:
Hi, I'm creating a web application that runs a java application to handle some processing in libraries that I've only been able to find written in java. In VB.Net I'm creating a Process with...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
blazedaces
by: blazedaces | last post by:
So in another thread I posted someone suggested I monitor the heap space usage using jstat, which lead me to jconsole which does something similar, but is more of a GUI. The problem I'm having...
6
by: itsraghz | last post by:
Dear All, I have an issue with destroy() method of java.lang.Process class. All what I am trying to do is, controlling the execution of one program through another. Let's say, Program B has to be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.