如何终止在Linux中特定端口上运行的进程?

本文翻译自:How to kill a process running on particular port in Linux?

I tried to close the tomcat using ./shutdown.sh from tomcat /bin directory. 我试图使用tomcat /bin目录中的./shutdown.sh关闭tomcat。 But found that the server was not closed properly. 但是发现服务器没有正确关闭。 And thus I was unable to restart 因此我无法重新启动
My tomcat is running on port 8080 . 我的tomcat在端口8080上运行。

I want to kill the tomcat process running on 8080 . 我想杀死运行在8080上的tomcat进程。 I first want to have the list of processes running on a specific port (8080) in order to select which process to kill. 我首先要具有在特定端口(8080)上运行的进程的列表,以便选择要杀死的进程。


#1楼

参考:https://stackoom.com/question/mbPe/如何终止在Linux中特定端口上运行的进程


#2楼

Use the command 使用命令

 sudo netstat -plten |grep java

used grep java as tomcat uses java as their processes. 使用grep java作为tomcat使用java作为其进程。

It will show the list of processes with port number and process id 它将显示带有端口号和进程ID的进程列表

tcp6       0      0 :::8080                 :::*                    LISTEN      
1000       30070621    16085/java

the number before /java is a process id. /java之前的数字是进程ID。 Now use kill command to kill the process 现在使用kill命令杀死进程

kill -9 16085

-9 implies the process will be killed forcefully. -9表示该过程将被强制终止。


#3楼

This fuser 8080/tcp will print you PID of process bound on that port. fuser 8080/tcp将为您打印该端口上绑定的进程的PID。

And this fuser -k 8080/tcp will kill that process. 而这个fuser -k 8080/tcp将终止该进程。

Works on Linux only. 仅适用于Linux。 More universal is use of lsof -i4 (or 6 for IPv6). 更通用的是使用lsof -i4 (对于IPv6, lsof -i4 6)。


#4楼

This prints to stdout the process ids of everything running on <port_number> : 这将打印以输出在<port_number>上运行的所有进程的进程ID:

fuser -n tcp <port_number> 

It also prints some stuff to stderr, so: 它还会向stderr打印一些内容,因此:

fuser -n tcp <port_number> 2> /dev/null

We can then supply these process ids to the kill command: 然后,我们可以将这些进程ID提供给kill命令:

sudo kill $(fuser -n tcp <port_number> 2> /dev/null)

You could also put this in a function if you do it a lot: 如果您经常这样做,也可以将其放在函数中:

function killport() {
    sudo kill $(fuser -n tcp $1 2> /dev/null)
}

#5楼

Linux : You can use this command if you know the port : Linux :如果知道端口,则可以使用此命令:

netstat -plten | grep LISTEN | grep 8080

AIX : AIX

netstat -Aan | grep LISTEN | grep 8080

You then take the first column (example: f100050000b05bb8) and run the following command: 然后,您选择第一列(例如:f100050000b05bb8)并运行以下命令:

rmsock f100050000b05bb8 tcpcb

kill process. 杀死进程。


#6楼

To know the pid of service running on particular port : 要知道在特定端口上运行的服务的pid:

netstat -tulnap | grep :*port_num*

you will get the description of that process. 您将获得该过程的描述。 Now use kill or kill -9 pid. 现在使用kill或kill -9 pid。 Easily killed. 容易被杀死。

eg 例如

netstat -ap | grep :8080

tcp6       0      0 :::8080       :::*    LISTEN      1880/java 

Now: 现在:

kill -9 1880

Remember to run all commands as root 记住要以root身份运行所有命令

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值