Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package foroverflow;
- public class ForOverflow {
- public static void main(String[] args) throws Exception {
- System.out.print("Ingrese la cantidad de procesos a detener: ");
- ForOverflow1 obj = new ForOverflow1();
- obj.Procesos_aaa();
- ForOverflow2.killProcess();
- }
- }
- package foroverflow;
- import java.util.Scanner;
- public class ForOverflow1 {
- Scanner in = new Scanner(System.in);
- String Procesos[] = new String [in.nextInt()];
- public void Procesos_aaa() {
- in.nextLine();
- for(int con = 0; con < Procesos.length; con++) {
- System.out.print("Ingresa el nombre del " + ++con + " proceso, (x ej: chrome.exe): ");
- Procesos[--con] = in.nextLine();
- }
- }
- public String[] getProcesos() {
- return Procesos;
- }
- }
- package foroverflow;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- public class ForOverflow2 {
- private static final String TASKLIST = "tasklist";
- private static final String KILL = "taskkill /F /IM ";
- public static boolean isProcessRunning(String serviceName) throws Exception {
- Process p = Runtime.getRuntime().exec(TASKLIST);
- BufferedReader reader = new BufferedReader(new
- InputStreamReader(p.getInputStream()));
- String line;
- while ((line = reader.readLine()) != null) {
- System.out.println(line);
- if (line.contains(serviceName)) {
- return true;
- }
- }
- return false;
- }
- public static void killProcess() throws Exception {
- ForOverflow1 obj = new ForOverflow1();
- for (String aaa : obj.getProcesos()) {
- Runtime.getRuntime().exec(KILL + aaa);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement