Friday, August 23, 2013

Linux: Kill a process listening to a port

Some times we need to kill processes listening to a some port.More often address already in use messages occur due to some process already listening to a given port.

Method 1:
If you want to use backtick not regular tick

sudo kill 'sudo lsof -t -i:port' 

Eg: sudo kill 'sudo lsof -t -i:9000' //Kill process listnining to port 9000


Method 2: 
Some times above method doesn't work then you can use $() for command interpolation

sudo kill $(sudo lsof -t -i:port)

Eg: kill $(sudo lsof -t -i:9000) //Kill process listnining to port 9000

No comments:

Post a Comment