1 24 package org.objectweb.cjdbc.scenario.tools.util; 25 26 import java.io.BufferedReader ; 27 import java.io.InputStreamReader ; 28 import java.util.StringTokenizer ; 29 30 36 public class KillJava 37 { 38 39 private String killTarget; 40 private int totalCount; 41 42 48 public KillJava(String killTarget) 49 { 50 this.killTarget = killTarget; 51 totalCount = 0; 52 } 53 54 60 public KillJava() 61 { 62 killTarget = "org.hsqldb.Server"; 63 totalCount = 0; 64 } 65 66 67 73 public void execute() throws Exception 74 { 75 String command = "ps -aux"; 77 Process p = Runtime.getRuntime().exec(command); 78 BufferedReader br = new BufferedReader (new InputStreamReader (p 79 .getInputStream())); 80 String line = ""; 81 StringTokenizer tokenizer; 82 int count = 0; 83 while ((line = br.readLine()) != null) 84 { 85 if (line.indexOf("java") != -1 && line.indexOf(killTarget) != -1 86 && line.indexOf("KillJava") == -1) 87 { 88 tokenizer = new StringTokenizer (line); 90 tokenizer.nextToken(); 91 String processNumber = tokenizer.nextToken(); 92 Runtime.getRuntime().exec("kill -9 " + processNumber); 94 count++; 95 } 96 } 97 totalCount += count; 98 if (count > 0) 99 execute(); 100 else 101 System.out.println("Terminated "+totalCount+" processes"); 102 } 103 } | Popular Tags |