How to kill a process by port number

Today, I wanted to run my Tomcat server, but for some reason, the old instance was still running. The terminal returns the following message:



The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.


Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.

The message is quite clear, but how to kill the server. I will show you how you can achieve this for Unix and Windows.

As first you need to figure out the process identifier (PID). The PID is used as a unique identifier in your operating system.

// Windows
netstat -ano | findstr :8080

netstat is a command to display network connections. The arguments are used to display all active connections as numerical name and add the PID to every process. The findstr command can be used to filter the result to your desired value.

// Unix
lsof -i:8080

lsof stands for ‘List Open Files’. It shows all sockets and other values, which are opened by a process. The argument -i list all IP sockets and followed by the port to filter the process to the one we are looking for.

Now we can see the process identifier in the PID column and start to kill the process. In my example, the PID is 12345.

// Windows
Taskkill /PID  12345 /F

taskkill is the command which triggers the termination of our process. The second and third argument is a filter to identify the process which needs to be terminated. The last argument /F is used to force the command.

// Unix
kill -9 12345

kill is the command which sends a signal to the process. The -9 is the argument to kill the process. The last argument is the PID number we want to terminate.

If you want to learn more about the commands you can follow the links. They lead you either to the Microsoft Docs or to the POSIX programmers manual.


Leave a comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.