2020-07-09 09:43:57 版本 : 边缘网关用到的查询Linux进程方法
作者: 倪嗣成 于 2020年07月09日 发布在分类 / 物联网组 / 边缘接入网关 下,并于 2020年07月09日 编辑
 历史版本

修改日期 修改人 备注
2020-07-09 09:45:29[当前版本] 倪嗣成 创建版本
2020-07-09 09:44:46 倪嗣成 创建版本
2020-07-09 09:43:57 倪嗣成 创建版本
2020-07-09 09:41:07 倪嗣成 创建版本

    public static String getLinuxPID(String command) {
        BufferedReader reader = null;
        try {
            //显示所有进程
            Process process = Runtime.getRuntime().exec("ps -ef");
            reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                if (line.contains(command)) {
                    String[] strs = line.split("\\s+");
                    return strs[1];
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {

                }
            }
        }
        return null;
    }

历史版本-目录  [回到顶端]
    知识分享平台 -V 4.8.7 -wcp