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. curl命令测试服务器是否支持断点续传

     通过curl命令测试服务器是否支持断点续传 curl -i --range 0-9 http://www.baidu.com/img/bdlogo.gif HTTP/1.1 206 Partial ...

  2. [转]C# 动态调用 WebService

    通常我们在程序中需要调用WebService时,都是通过“添加Web引用”,让VS.NET环境来为我们生成服务代理,然后调用对应的Web服务.这样是使工作简单了,但是却和提供Web服务的URL.方法名 ...

  3. Spring - @ManagedResource, @ManagedOperation, @ManagedAttribute

    总结 通过annotation (@ManagedResource, @ManagedOperation, @ManagedAttribute)注解注册MBean到JMX实现监控java运行状态 参考 ...

  4. bzoj1057: [ZJOI2007]棋盘制作 [dp][单调栈]

    Description 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源 于易经的思想,棋盘是一个8*8大小的黑白相间的方阵,对应八八六十四卦,黑白对应 ...

  5. 如何理解Vue的render函数

    第一个参数(必须) - {String | Object | Function} <!DOCTYPE html> <html lang="en"> < ...

  6. C 函数指针详解

    一 通常的函数调用    一个通常的函数调用的例子://自行包含头文件 void MyFun(int x); //此处的申明也可写成:void MyFun( int ); int main(int a ...

  7. MFC-按行读取TXT数据

    TXT中数据格式如下: 1 23 4 0 4 10 …… 要实现的功能是:定义一个函数,每次调用时从TXT文档中读一个整数 ,赋值给变量.同时,文件位置向下移动一行,以便下次调用时读取下一行的数据. ...

  8. 《转》python

    转自http://www.cnblogs.com/BeginMan/archive/2013/06/03/3114974.html 1.print语句调用str()函数显示,交互式解释器调用repr( ...

  9. 最短路(模板Dtra

    #include<iostream> #include<cstdio> #include<cstring> using namespace std; const i ...

  10. 【python】快速排序

    快速排序思想和C++的差不多,主要是通过写排序对python的语法更加了解. # 快速排序 def qsort(arr, left, right): if left >= right: retu ...