How to Kill Java Process in Linux Operating System using Java Code
Java Code for killing the Java process in Linux OS.
Hi,Here I have written the small snippet for killing the java running process in linux OS.
public void checkprocess()
{
String s = null;
int x=0;
try
{
Process p = Runtime.getRuntime().exec("jps"); //JPS command is used for showing all the java running process with ID.
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((s = stdInput.readLine()) != null)
{
String[] tokens = s.split(" ");
if(tokens.length!=2)
{
throw new IllegalArgumentException();
}
String commandid = tokens[0];
String prcess = tokens[1];
System.out.println("Processes Name is : "+prcesss);
if(prcs.equals("Process Name which you want to kill"))
{
Process p1 = Runtime.getRuntime().exec("kill "+commandid+"");
x++;
}
if(x>1)
{
System.out.println("Processes Name is : "+prcess);
System.out.println("Processes ID is : "+commandid);
System.exit(0);
}
}
}
catch (IOException e)
{
System.out.println("exception : "+e);
}
}
Bollywood News in Hindi - Check out the latest Bollywood news, new Hindi movie reviews, box office collection updates
ReplyDeletevenom 2 Let There Be Carnage Full Movie Download & Review
83 Full Movie Download & Review