Friday 18 February 2011

Determine which application is using a particular port

Say you try to install an application which needs to use port 80. But during or after the installation, the application is not able to launch because port 80 is already in use, how do you determine which application is holding on to port 80?

In Windows, it is simple and fairly straight forward.

Follow the steps below:
1. Issue the following command to check which process is using port 80:
netstat -aon | findstr 0.0:80

NOTE: If you wanted to check for any other port number, replace the "80" in the command above with the port number of choice.2. The output could look like this:
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 2920

For the example above, referring to the number highlighted in yellow, this is the process id which is using/listening to port 80. The process id is assigned by the OS to an application/service which is running (it could be running in the background)

3. Issue the following command to get the name of the process which as the process id (as shown in the yellow text above - this value can be any number as assigned by the system, i.e. never fixed)
tasklist | findstr 2920

4. This command would yield an output which would have the following format:
httpd.exe 2920 Console 0 12,724 K

Based on the example above, the application using process id 2920 is "httpd.exe".

So, from here, you can see that port 80 is being used by process id 2920, where process id 2920 was assigned by the OS to httpd.exe which is running in the background (NOTE: this is on my system - If I was to restart my PC or stop httpd.exe and restart it, the process id would highly likely not be the same)