How to kill a process running on particular port in Linux?

Sometimes we start a server instance of some process but found the port on which the particular process needs to run is already occupied by some other process, or in case of a server already an instance is running.

So how can we release the port from the particular process?


To free a port from a process, we need to stop that process, but what if we are unable to stop that process like process may be got hanged or is in deadlock. then in that scenario, we need to kill that process.


To kill a process we have follow two steps

               1)   Find the PID(process ID) of the process
               2)   Run the process kill command and pass the PID in it.

Step 1:Finding PID from port number :
    $ sudo netstat -nlp | grep :<port_number>
    tcp  0  0  0.0.0.0:80  0.0.0.0:*  LISTNEN   125004/nginx

Step 2: Kill the process :
     kill -9 125004

Note:-** Here '-9' refers that the process will be killed forcefully.

There are other options also like 'lsof' and 'fuser'.

Comments

Popular Posts