在我的应用程序,在运行时,我希望能够确定是否正在使用特定端口(很容易做到这一点)在运行时检查端口使用情况?
public static boolean portAvailable(int port) {
try (Socket ignored = new Socket("localhost", port)) {
return false;
} catch (IOException ignored) {
return true;
}
}
,但我也想获得尽可能多的信息尽可能关于谁在使用此端口。东西像进程ID,名称等。我该如何去做这件事?
'windows'或'* nix'平台? – Saravana
理想情况下我可以同时支持,但* nix是最低要求 – stikku