zoukankan      html  css  js  c++  java
  • java 检查进程是否存在

    以nginx进程为例子

    private final static String NAME_STRING = "nginx.exe";
    
    //传入进程名称processName
    	public static boolean findProcess() {
    		BufferedReader bufferedReader = null;
    	    try {
    	        Process proc = Runtime.getRuntime().exec("tasklist -fi " + '"' + "imagename eq " + NAME_STRING +'"');
    	        bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    	        String line = null;
    	        while ((line = bufferedReader.readLine()) != null) {
    	            if (line.contains(NAME_STRING)) {
    	                return true;
    	            }
    	        }
    	        return false;
    	    } catch (Exception ex) {
    	        ex.printStackTrace();
    	        return false;
    	    } finally {
    	        if (bufferedReader != null) {
    	            try {
    	                bufferedReader.close();
    	            } catch (Exception ex) {}
    	        }
    	    }
    	}
    	
    

      

  • 相关阅读:
    JavaScript和DOM
    CSS补充以及后台页面布局
    HTML标签和CSS基础
    基于SQLAlchemy实现的堡垒机
    PymySQL
    SQLAlchemy
    负数取模
    list
    算法(3)
    python初识(3)
  • 原文地址:https://www.cnblogs.com/wangjinyu/p/10803615.html
Copyright © 2011-2022 走看看