Windows:

    List<String> tasklist=new ArrayList<String>();

    try {
      Process process = Runtime.getRuntime().exec(cmdstr);
      BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
      while (in.hasNextLine()) {
      String p = in.nextLine();
                     if (p.contains("java.exe")) {
                          p = p.replaceAll("\\s+", ",");
                          String[] arr = p.split(",");
                          tasklist.add(arr[1]);//此处要进行判断
                    }
             }
             in.close();

Centos:

  public static List<String> getPidFromCentos(){
            List<String> tasklist=new ArrayList<String>();
            Process process = null;
            BufferedReader br = null;
            try {
                String[] cmd ={"sh","-c","ps -ef | grep java"};
                process = Runtime.getRuntime().exec(cmd);
                br = new BufferedReader(new InputStreamReader(
                            process.getInputStream()), 1024);
                String line = null;
                Pattern pattern = Pattern.compile("\\S*\\s*([0-9]*).*");
                Matcher matcher = null;
                while ((line = br.readLine()) != null) {
                    matcher = pattern.matcher(line);
                    if (matcher.find()) {
                        tasklist.add(matcher.group(1));
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (process != null) {
                    int retval = 0;
                    try {
                        retval = process.waitFor();
                        System.out.println("retval = " + retval);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } finally {
                        if (br != null) {
                            try {
                                br.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
            return tasklist;
        }

  

Windows与Linux获取进程集合的方法的更多相关文章

  1. windows 内核下获取进程路径

    windows 内核下获取进程路径 思路:1):在EPROCESS结构中获取.此时要用到一个导出函数:PsGetProcessImageFileName,申明如下: NTSYSAPI UCHAR *  ...

  2. [转]❲阮一峰❳Linux 守护进程的启动方法

    ❲阮一峰❳Linux 守护进程的启动方法 "守护进程"(daemon)就是一直在后台运行的进程(daemon). 本文介绍如何将一个 Web 应用,启动为守护进程. 一.问题的由来 ...

  3. Windows 和  Linux 下 禁止ping的方法

    Windows 和Linux 下 禁止ping的方法 目的: 禁止网络上的其他主机或服务器ping自己的服务器 运行环境: Windows 03.08  linux 方法: Windows 03下: ...

  4. Linux 命令详解(六)Linux 守护进程的启动方法

    Linux 守护进程的启动方法 http://www.ruanyifeng.com/blog/2016/02/linux-daemon.html

  5. linux --> 获取进程执行时间

    获取进程执行时间 一.时间概念 在linux下进行编程时,可能会涉及度量进程的执行时间.linux下进程的时间值分三种: 时钟时间(real time):指进程从开始执行到结束,实际执行的时间. 用户 ...

  6. Linux下进程隐藏的方法及其对抗

    零.背景 在应急响应中,经常碰到ps命令和top命令查不到恶意进程(异常进程)的情况,会对应急响应造成很大的影响.轻则浪费时间,重则排查不出问题,让黑客逍遥法外.所以这篇博客研究学习如何对抗linux ...

  7. Unix/Linux获取进程的详细信息

    Linux的进程的信息都记录在/proc/<pid>/下面,其实常用的ps.top命令也是从这里读取信息的.常用的信息有: cmd(命令).cmdline(完整的命令行参数).envrio ...

  8. [Linux] - Windows与Linux网络共享文件夹挂载方法

    Windows与Linux网络SMB方式文件夹共享挂载 本示例系统: Windows 2003+ Linux-Centos/Ubuntu 本示例全为命令行操作,如何使用Windows.Linux命令行 ...

  9. c++ windows与linux通信中文乱码问题解决方法

    在linux中默认编码方式是UTF-8,在Windows下默认编码方式时GB2312.因此,在Windows和Linux进行通信的时候,如果没有进行转码则会出现乱码问题.因此,需要进行UTF-8和GB ...

随机推荐

  1. selenium如何操作页面树状列表

    selenium如何操作页面树状列表??举个例子:我要怎么操作如下图所示的树状结构列表?我要对这个树状结构列表做什么操作? 一.思路 1.根据driver.find_element_by_xpath( ...

  2. SpringCloud+Eureka+Feign+Ribbon+zuul的简化搭建流程和CRUD练习

    环境:win10--idea2019--jdk8 1.搭建Eureka服务模块 1.1 新建eureka服务模块(Sping Initializr) 取名为eureka-server,并添加如下Dep ...

  3. python基础教程2第20章 项目1:即时标记

    simple_markup.py import sys, re from util import * print('<html><head><title>...&l ...

  4. php获取数组中指定值的下标

    public function find_by_foreach($array,$find)//$array数组 $find需要查找的值 { foreach ($array as $key => ...

  5. 「题解」:07.16NOIP模拟T2:通讯

    问题 B: 通讯 时间限制: 1 Sec  内存限制: 256 MB 题面 题目描述 “这一切都是命运石之门的选择.” 试图研制时间机器的机关SERN截获了中二科学家伦太郎发往过去的一条短 信,并由此 ...

  6. NX二次开发-UFUN判断文件是否存在UF_CFI_ask_file_exist

    #include <uf.h> #include <uf_ui.h> #include <uf_cfi.h> UF_initialize(); //判断文件是否存在 ...

  7. NX二次开发-UFUN读取工程图注释UF_DRF_ask_text_data

    1 NX11+VS2013 2 3 4 #include <uf.h> 5 #include <uf_ui.h> 6 #include <uf_drf.h> 7 8 ...

  8. ios 查看UIView的层次继承关系工具

    http://stackoverflow.com/questions/5150186/how-do-i-inspect-the-view-hierarchy-in-ios https://github ...

  9. 转-Windows下anaconda简单使用教程

    转自:https://www.cnblogs.com/Dota-wiki/p/7871838.html Anaconda is a completely free Python distributio ...

  10. spring boot jpa没有自动生成表的原因——加上@Entity

    别人的项目弄了好久,竟然是忘记加注解,当然配置文件还是要配置jpa的,pom也要依赖jpa. @Entity jpa: hibernate: ddl-auto: update show-sql: tr ...