Languages
[Edit]
EN

Linux - kill process listening on specific port

4 points
Created by:
JustMike
26670

In this short article we would like to show how to kill process that listen on specific port in Linux.

Quick solution:

kill -9 $(lsof -t -i:8080)

Where: 8080 is number of used port by process that we want to kill.

How it works?

lsof allows to return details of opened files - in Linux common politics is to represent all things by files. With -i:8080 we are able to find informations about processes that use 8080 port. We want to get only PID, so -t parameter is useful to do it - returning only process ID (PID).

kill program stops process on kernel level becouse of -9 parameter. In above case using result of lsof command as PID parameter.

More safe way example

Alternatively for save we can do all steps manually to be sure that proper program was killed.

Simple steps:

  1. display processes that uses port 8080,
    Command:
    lsof -w -i:8080

    Output:

    COMMAND   PID  USER  FD   TYPE  DEVICE  SIZE/OFF  NODE NAME
    node    16908  john  21u  IPv4  220968       0t0  TCP *:8080 (LISTEN)
  2. kill selected process (in out case it is PID 16908),
    Command:
    kill -9 16908
    Output:
    Killed
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - friendly IT community for everyone.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join