Reputation:
I am working on a Java EE Application in a Windows environment. (I am using 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.
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.
Upvotes: 83
Views: 364485
Reputation: 133
If someone is trying in windows 10 pro, netstat -anp might not list any connection, so try netstat -an and add | find to find your desire port
for example I want to check in port 65432 is being currently used then I do
netstat -an|find "65432"
Upvotes: 3
Reputation: 1177
netstat -ano| grep
this will give status of the port if being used or not
Upvotes: 0
Reputation: 1182
If you prefer Powershell, use this. You will get the name of the process.
PS C:\Users\Administrator> Get-Process -Id (Get-NetTCPConnection -LocalPort 9093).OwningProcess
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
6021 1464 2760976 2131548 290.39 25512 2 java
The PID is in Id
column, and it provides process name, as well.
If no process is using this port, you get a red error message.
If you want to kill the process with PID 25512, use
taskkill /PID 25512 /F
/F
means force, some processes cannot be killed without /F
Upvotes: 16
Reputation: 42272
If this is a purely local concern e.g. you want to run tomcat locally to test the application you're working on, something which often works is to configure port 0
. In that case when the application port-binds it will be allocated a random "ephemeral" port by the OS, which hopefully it logs out.
You'll have to check if that's supported by tomcat, but I would expect it is given past answers mentioning it.
It avoids having to hardcode ports and issues of TOCTOU, though it is obviously somewhat less convenient as you need to get the port you need to connect to every time.
The alternative is to just try out a bunch of free ports e.g. 8000[0] and 8888 are common alternate ports for HTTP servers. 8008 is also an official IANA alternate port though I can't remember ever seing it used.
[0] though officially assigned to iRDMI
Upvotes: 1
Reputation: 1120
You can use "netstat" to check whether a port is available or not.
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.
You have to put : before port number to get the actual output
Ex
netstat -anp | find ":8080"
Upvotes: 93
Reputation: 364
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 .
example : netstat -ano | find ":1900"
This gives you the result like this.
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
Upvotes: 23
Reputation: 29
It's (Get-NetTCPConnection -LocalPort "port no.").OwningProcess
Upvotes: 2
Reputation: 571
It's netstat -ano|findstr port no
Result would show process id in last column
Upvotes: 57