ubuntu kill processes on port code example

Example 1: kill port ubuntu

sudo kill -9 `sudo lsof -t -i:3002`

Example 2: kill a port in ubuntu

kill -9 $(sudo lsof -t -i:'portName')
//Ex. if portname is 3000
//then we will execute "kill -9 $(sudo lsof -t -i:3000)"

Example 3: force to kill any process port ubuntu

sudo kill -9 $(sudo lsof -t -i:9001)


lsof   - list of files(Also used for to list related processes)

-t     - show only process ID

-i     - show only internet connections related process

:9001  - show only processes in this port number

kill   - command to kill the process

-9     - forcefully

sudo   - command to ask admin privilege(user id and password).

Example 4: ubuntu kill process on a port

sudo kill -9 $(sudo lsof -t -i:4000)