windows 如何确保某个端口不被任何其他进程占用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8817500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:06:20  来源:igfitidea点击:

How to make sure that a certain Port is not occupied by any other process

windowsnetworking

提问by Aravind

I am working on a Java EE Application in a Windows environment. (I am using Windows 7)

我正在 Windows 环境中开发 Java EE 应用程序。(我使用的是 Windows 7)

I am using Tomcat Server, unfortunately port number 8080 is busy (used by Oracle). Now I want to assign a different port to Tomcat.

我正在使用 Tomcat 服务器,不幸的是端口号 8080 正忙(由 Oracle 使用)。现在我想为 Tomcat 分配一个不同的端口。

So before changing inside conf/server.xml file, I want to make sure that a certain port is not occupied by any other process and it's free.

所以在更改 conf/server.xml 文件之前,我想确保某个端口没有被任何其他进程占用并且它是免费的。

回答by Aravind

You can use "netstat" to check whether a port is available or not.

您可以使用“netstat”来检查端口是否可用。

Use the netstat -anp | find "port number"command to find whether a port is occupied by an another process or not. If it is occupied by an another process, it will show the process id of that process.

使用该netstat -anp | find "port number"命令查看端口是否被其他进程占用。如果它被另一个进程占用,它将显示该进程的进程ID。

You have to put : before port number to get the actual output

您必须在端口号之前放置:才能获得实际输出

Ex netstat -anp | find ":8080"

前任 netstat -anp | find ":8080"

回答by Anup

It's netstat -ano|findstr port no

它是 netstat -ano|findstr port no

Result would show process id in last column

结果将在最后一列中显示进程 ID

回答by Nikhil Shaw

netstat -ano|find ":port_no"will give you the list.
a: Displays all connections and listening ports.
n: Displays addresses and port numbers in numerical form.
o: Displays the owning process ID associated with each connection .

netstat -ano|find ":port_no"会给你名单。
a:显示所有连接和监听端口。
n:以数字形式显示地址和端口号。
o:显示与每个连接关联的拥有进程 ID。

example : netstat -ano | find ":1900"This gives you the result like this.

示例:netstat -ano | find ":1900"这会给你这样的结果。

UDP    107.109.121.196:1900   *:*                                    1324  
UDP    127.0.0.1:1900         *:*                                    1324  
UDP    [::1]:1900             *:*                                    1324  
UDP    [fe80::8db8:d9cc:12a8:2262%13]:1900  *:*                      1324

回答by Shivam Tiwari

It's (Get-NetTCPConnection -LocalPort "port no.").OwningProcess

它是 (Get-NetTCPConnection -LocalPort "port no.").OwningProcess