Find Process ID of Process using given port in Windows
Once a while it happens that you try to start Tomcat and it complains “Port 8080 required by Tomcat v7.0 Server at localhost is already in use”. So that means there is already a process running in background that has occupied 8080 port. So how to identify the process in Windows task manager that is using port 8080? I am sure there must be a javaw.exe. But is there a better way to identify which process in windows is using a given port number? Yes…
How to Find Process ID of process that uses a Port in Windows
Our friend netstat will help us in identifying the process. netstat can list the running process and display information such as process id, port, etc. From this list we can filter the processes that has given port using findstr command.
List process by port number
netstat -ano | findstr 8080
Proto Local Address Foreign Address State PID
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 29848
-a – Displays all connections and listening ports.
-o – Displays the owning process ID associated with each connection.
-n – Displays addresses and port numbers in numerical form.
We can use netstat to list all the processes.
List all processes by PID
Kill the Process by PID
Once we identify the process PID, we can kill the process with taskkill command.
taskkill /F /PID 12345
Where /F specifies to forcefully terminate the process(es). Note that you may need an extra permission (run from admin) to kill some certain processes.
Or else you can use our old trusted Windows Task Manager to kill the process for given process id. If PID is not visible in your task manager then you can enable it by Right clicking on table header under Details tab, click Select Columns and then check PID.