获得占用指定端口的进程ID和进程名称
来源:互联网 发布:阿里云管理终端密码 编辑:程序博客网 时间:2024/05/18 03:52
// 得到进程ID
public static String getPID(String port)
{
InputStream is = null;
BufferedReader br = null;
String pid = null;
try
{
String[] args = new String[]
{ "cmd.exe", "/c", "netstat -aon|findstr", port };
is = Runtime.getRuntime().exec(args).getInputStream();
br = new BufferedReader(new InputStreamReader(is));
String temp = "";
while((temp = br.readLine()) != null)
{
if ((temp.indexOf(":80 ")>0)&& (temp.indexOf("LISTENING")>0))
{
String[] strs = temp.split("//s");
pid = strs[strs.length - 1];
break;
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return pid;
}
// 根据进程ID得到映像名称
public static String getProgramName(String pid)
{
InputStream is = null;
BufferedReader br = null;
String programName = null;
try
{
String[] args = new String[]
{ "cmd.exe", "/c", "tasklist|findstr", pid };
is = Runtime.getRuntime().exec(args).getInputStream();
br = new BufferedReader(new InputStreamReader(is));
String temp = br.readLine();
if (temp != null)
{
String[] strs = temp.split("//s");
programName = strs[0];
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return programName;
}
// 根据映像名称关闭进程
public static void killTask(String programName)
{
String[] args = new String[]
{ "Taskkill", "/f", "/IM", programName };
try
{
Runtime.getRuntime().exec(args);
}
catch (IOException e)
{
e.printStackTrace();
}
}
- 获得占用指定端口的进程ID和进程名称
- windows 下查看使用端口的进程ID和名称
- 关闭占用指定端口的进程
- 关闭占用指定端口的进程
- 查看占用指定端口进程的方法
- 杀掉占用指定端口的进程
- 获得指定进程名的进程ID列表
- MFC获得指定进程的ID,路径及终止进程
- 得到端口号进程ID和关闭指定端口
- windows和linux杀死指定端口占用进程
- 查看当前占用某端口的进程ID
- linux 查看端口占用进程ID
- linux 查看端口占用进程ID
- 查看指定端口号被哪个进程占用的情况
- 通过 PS 指令获得指定进程名称的 PID
- cmd -- 查询端口占用情况、获取进程名称、杀死进程
- windows 查看监听指定端口号的进程id
- 80端口被进程号为Pid4,名称为NT kernel & System的系统进程占用
- jaxb jaxp使用xml来生成动态页面 - xml xsd xsl ( xpath xslt ) css 概念入门
- spring bean的scope属性解决struts action单实例问题
- 后台代码里执行弹出脚本方法!(Response.Write)
- flickr api 笔记 之 获取小图
- 中文分词有关资料
- 获得占用指定端口的进程ID和进程名称
- 用Java实现 上传
- 低处的温暖
- 【CSAPP读书笔记】过程及其相关操作的分析(经典:包括函数调用过程详解)
- FCKEditor图片上传“没有权限”的问题
- 写出内存分配和释放的函数,并指出区别
- win7右键管理无法打开解决方案
- 在linux中如何编译C程序,使之成为可执行文件?如何调试?
- (转)C++界面库的抉择