Windows与Linux获取进程集合的方法
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获取进程集合的方法的更多相关文章
- windows 内核下获取进程路径
windows 内核下获取进程路径 思路:1):在EPROCESS结构中获取.此时要用到一个导出函数:PsGetProcessImageFileName,申明如下: NTSYSAPI UCHAR * ...
- [转]❲阮一峰❳Linux 守护进程的启动方法
❲阮一峰❳Linux 守护进程的启动方法 "守护进程"(daemon)就是一直在后台运行的进程(daemon). 本文介绍如何将一个 Web 应用,启动为守护进程. 一.问题的由来 ...
- Windows 和 Linux 下 禁止ping的方法
Windows 和Linux 下 禁止ping的方法 目的: 禁止网络上的其他主机或服务器ping自己的服务器 运行环境: Windows 03.08 linux 方法: Windows 03下: ...
- Linux 命令详解(六)Linux 守护进程的启动方法
Linux 守护进程的启动方法 http://www.ruanyifeng.com/blog/2016/02/linux-daemon.html
- linux --> 获取进程执行时间
获取进程执行时间 一.时间概念 在linux下进行编程时,可能会涉及度量进程的执行时间.linux下进程的时间值分三种: 时钟时间(real time):指进程从开始执行到结束,实际执行的时间. 用户 ...
- Linux下进程隐藏的方法及其对抗
零.背景 在应急响应中,经常碰到ps命令和top命令查不到恶意进程(异常进程)的情况,会对应急响应造成很大的影响.轻则浪费时间,重则排查不出问题,让黑客逍遥法外.所以这篇博客研究学习如何对抗linux ...
- Unix/Linux获取进程的详细信息
Linux的进程的信息都记录在/proc/<pid>/下面,其实常用的ps.top命令也是从这里读取信息的.常用的信息有: cmd(命令).cmdline(完整的命令行参数).envrio ...
- [Linux] - Windows与Linux网络共享文件夹挂载方法
Windows与Linux网络SMB方式文件夹共享挂载 本示例系统: Windows 2003+ Linux-Centos/Ubuntu 本示例全为命令行操作,如何使用Windows.Linux命令行 ...
- c++ windows与linux通信中文乱码问题解决方法
在linux中默认编码方式是UTF-8,在Windows下默认编码方式时GB2312.因此,在Windows和Linux进行通信的时候,如果没有进行转码则会出现乱码问题.因此,需要进行UTF-8和GB ...
随机推荐
- leetcode-第11场双周赛-5088-等差数列中缺失的数字
题目描述: 自己的提交: class Solution: def missingNumber(self, arr: List[int]) -> int: if len(arr) == 2: re ...
- Batch - forfiles 命令详解
forfiles 命令详解 C:\Users\cuixunxu>forfiles /? FORFILES [/P pathname] [/M searchmask] [/S] [/C comma ...
- faster-rcnn代码阅读-rpn-data层
这一节讲述rpn-data层,和这一层有关的结构图如下: rpn-data层的prototxt定义如下: layer { name: 'rpn-data' type: 'Python' bottom: ...
- Python 爬虫-抓取小说《盗墓笔记-怒海潜沙》
最近想看盗墓笔记,看了一下网页代码,竟然不是js防爬虫,那就用简单的代码爬下了一节: """ 爬取盗墓笔记小说-七星鲁王宫 """ from ...
- 在360的兼容模式下关于innerHTML=“”,引发的问题
innerHTML属性,可以动态设置和修改dom,但是在360的兼容模式下回存在一些问题...... var dBody = document.body; var fatherDom = docume ...
- iOS开发inputView和inputAccessoryView
1.简介 起初看到这两个属性是在UIResponder中,只是可读的: @property (nullable, nonatomic, readonly, strong) __kindof UIVie ...
- 分类-回归树模型(CART)在R语言中的实现
分类-回归树模型(CART)在R语言中的实现 CART模型 ,即Classification And Regression Trees.它和一般回归分析类似,是用来对变量进行解释和预测的工具,也是数据 ...
- Flink 1.6.0 Windows操作
原文连接 https://ci.apache.org/projects/flink/flink-docs-release-1.6/dev/stream/operators/windows.html W ...
- hbase 集群搭建(公司内部测试集群)
我用的是cdh4.5版本:配置文件:$HBASE_HOME/conf/hbase-env.shexport JAVA_HOME=$JAVA_HOMEexport JAVA_HOME=/home/had ...
- <读书笔记>001-以解决问题为导向的python编程实践
以解决问题为导向的python编程实践 0.第0章:计算机科学 思考:计算机科学是否为计算机编程的简称? 编程的困难点:1.同时做2件事(编程语言的语法.语义+利用其解决问题) 2.什么是好程序(解 ...