给定其进程id,是否可以使用java查找进程正在使用的端口? [英] Is there a way to find a port being used by process, given its process id , using java?

查看:140
本文介绍了给定其进程id,是否可以使用java查找进程正在使用的端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定Java中进程的进程ID,是否有一种方法可以找到由Java进程打开的端口? 需要使用Java来找到它,因为它必须与平台无关

Is there a way to find a port opened by java process, given the process id of the process in java? Need to find it using java as it has to be platform independent

给出一个进程ID:输出该进程正在使用的所有端口/套接字连接.

Given a process id : output any port/socket connections being used by that process.

给出的东西很少: 进程在同一个jvm中运行. 该进程仅使用1个端口/套接字, 为其指定了Pid.

Few things given: Process running in same jvm. There is only 1 port/socket being used by that Process, for which the Pid is given.

不能执行平台特定的命令,例如ps -au | grep pid | ...

Can not do platform specific commands like ps -au | grep pid | ...

推荐答案

答案是否定的.什么进程具有什么端口根本不是Java应用程序可用的信息.您将需要JNI,它取决于操作系统.

The answer is no. What processes have what ports is not information available to java applications at all. You'd need JNI and it would depend on the operating system.

这篇关于给定其进程id,是否可以使用java查找进程正在使用的端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆