java 检测进程是否存在

 

 

public void isRunning() throws Exception {
	    String ls_1="";
		
	    Process process = Runtime.getRuntime().exec("TASKLIST /NH /FI \"IMAGENAME eq xxx.exe\"");
	    
	    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
	    
	    while ((ls_1=bufferedReader.readLine()) != null){
	    	if (ls_1.startsWith("xxx.exe")) {//根据进程名字判断
	    		//说明该进程存在
		}
	    }
	    process.waitFor();
	    process.destroy();
	}

 

你可能感兴趣的:(java 检测进程是否存在)