Menu

Showing posts with label PID. Show all posts
Showing posts with label PID. Show all posts

Port may already be in use

While running any application you may face an issue, that default port or port which our application required to start the process is occupied by some other process or service. In this article we will see how to fix this issue and how we can terminate the active process and service from that port and make it available for our new application. 
below are the steps which we need to follow for windows machine to free the port number.

Error log:

2019-11-22 23:38:18.329 ERROR 27240 --- [  restartedMain] o.apache.catalina.core.StandardService   : Failed to start connector [Connector[HTTP/1.1-8080]]

org.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-8080]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:256) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:198) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:300) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) [spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at jobtrees.JobTreesApplication.main(JobTreesApplication.java:25) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_221]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_221]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_221]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_221]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.1.RELEASE.jar:2.0.1.RELEASE]
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1020) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
... 18 common frames omitted
Caused by: java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_221]
at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_221]
at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_221]
at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source) ~[na:1.8.0_221]
at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source) ~[na:1.8.0_221]
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1150) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:591) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1018) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
... 19 common frames omitted

2019-11-22 23:38:18.343  INFO 27240 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-11-22 23:38:18.362  INFO 27240 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-11-22 23:38:18.364 ERROR 27240 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

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.

Action:

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.

How to fix?

To fix this issue and vacant the port you have to kill and stop the current service which is active and running on this port. to do so in your windows machine please follow the following steps.
Step1: Open command prompt(CMD).
Step2: Find the process ID which occupied the port. run the below command to find the PID. to know more on this you may refer our aticle find PID using port number.
netstat -aon | findstr <port number>
let say we want to find the active process ID which is running on port number 4502, hence we will run the below command. 
netstat -aon | findstr 4502
How to find process ID
Find process ID(PID)

Step3: after getting the process ID (PID) you may need to verify which service name or want to know the name of service, then execute the below command.
tasklist /fi "pid eq 8884"
Here, image name is the name of the service. 
How to find the service name using PID
Service name

Step4:
Now we need to stop or kill this active service so we could use another service on same port. To kill a service please run the below command.

taskkill /PID 8884 /F
How to remove an active service from a port.
kill active process/service

We have killed the process and service has been terminated it means now port 4502 is empty and no process or service is currently using that port. We may verify the same by running the command from step2 again.

if you have any query and suggestion, please feel free to pass.


How to find the PID using port number

What will you do if you don't know which program and service is registered and running on a port number?
Here we have a simple way to find that, which service and task is registered on a port number in just a few steps.
For example if you wants to check for the port number 4502, which service is running on this port, then first you have to find the PID(processing ID) associated with that port number. to do so follow the following steps:
  1. Open Command prompt(cmd) in your windows machine. Go to start and search for cmd. 
  2. Then copy the below command and paste in cmd window and hit enter.
  3. netstat -aon | findstr "<port number>"
  4. It will give you the result which have following:
    1. TCP: This contains the IP with port number.
    2. IP address: IP address which is serving and consuming this serving.
    3. Listening: Process ID(PID) associated with this port number.

Below is the screenshot:

How to find PID using port number in windows
How to find PID using port number in windows


Now follow my next blog to find the service or task using PID.

How to find which task is running on PID on Windows OS

If you know the PID, then you can easily track which service and task is active and running on that particular PID. If you don't know PID but you have port number then go through by my previous blog how to find the PID using port number.
To find the running service on PID do the following:


  1. Open Command prompt(cmd) in your windows machine. Go to start and search for cmd. 
  2. Then copy the below command and paste in cmd window and hit enter.
  3. tasklist /FI "PID eq <PID number>"
  4. It will give you the result which have following:
    1. Image Name: Name of the service and program which is executing on this PID.               
    2. PID : PID number
    3. Session Name: Where it is active, whether in the form of service or console.
    4. Session: How many session are active(number of active sessions) for this particular service or program.
    5. Mem Usage: How much memory this service and program is consuming in your machine.
Below is the screenshot:


how to find running service on a PID in windows
how to find running service on a PID in windows