How to kill a process on a port on ubuntu

2019-01-12 13:13发布

I am trying to kill a proccess in the command line for a specific port in ubuntu.

If I run this command I get the port:

sudo lsof -t -i:9001

so...now I want to run:

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

I get this error message:

ERROR: garbage process ID "lsof -t -i:9001".
Usage:
  kill pid ...              Send SIGTERM to every process listed.
  kill signal pid ...       Send a signal to every process listed.
  kill -s signal pid ...    Send a signal to every process listed.
  kill -l                   List all signal names.
  kill -L                   List all signal names in a nice table.
  kill -l signal            Convert between signal numbers and names.

I tried sudo kill 'lsof -t -i:9001' as well

标签: ubuntu port kill
19条回答
我只想做你的唯一
2楼-- · 2019-01-12 13:36

Use killport command :

sh killport 9001 

To Download shell ,you can use wget :

wget https://cdn.rawgit.com/abdennour/miscs.sh/e0aac343/killport
查看更多
一纸荒年 Trace。
3楼-- · 2019-01-12 13:36

Try this:

lsof -i :port

or 

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

or

kill -9 <pid>

or 

sh killport 8000
查看更多
We Are One
4楼-- · 2019-01-12 13:40

To kill a Process running on port number 9001

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).

for more you can visit my blog

查看更多
老娘就宠你
5楼-- · 2019-01-12 13:41

You want to use backtick not regular tick:

sudo kill `sudo lsof -t -i:9001`

If that doesn't work you could also use $() for command interpolation:

sudo kill $(sudo lsof -t -i:9001)
查看更多
虎瘦雄心在
6楼-- · 2019-01-12 13:41

Its two steps process:

  1. Know process id on port no. 8080 (can be any)
  2. Kill process of that id 8689 (can be different)

    fuser -n tcp 8080
    
    #o/p 8080/tcp    8689
    
    kill -9 8689
    
查看更多
戒情不戒烟
7楼-- · 2019-01-12 13:42
sudo kill `sudo lsof -t -i:9001`

you don't have to add the -9signal option

查看更多
登录 后发表回答