Linux 使用 BASH 如何杀死 TCP 端口 16969?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9825698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:21:01  来源:igfitidea点击:

Using BASH how can i kill TCP port 16969?

linuxbashubuntutcp

提问by

I have one application which use port TCP 16969. It requires sometimes a quick software kernel reboot on the fly. But if i launch it too fast, then i am locked with Exception in thread "main" java.net.BindException: Address already in use.

我有一个使用 TCP 16969 端口的应用程序。它有时需要快速重新启动软件内核。但是如果我启动它太快,那么我就会被锁定Exception in thread "main" java.net.BindException: Address already in use

So without any excuse i want to trigger my BASH script which can kill any running or listening port with 16969. But how can i do that?

所以没有任何借口我想触发我的 BASH 脚本,它可以用 16969 杀死任何正在运行或监听的端口。但是我该怎么做呢?

$ lsof -w -n -i tcp:16969 # this gives me a list of 50 lines but how can i tell apply kill to all on this port?

采纳答案by James C

I think that:

我觉得:

lsof -i tcp:22 | grep LISTEN | awk '{print }' | xargs kill

Should do the trick.

应该做的伎俩。

To double check what commands it wants to run before letting it loose add an echobefore the killlike this:

要在让它松散之前仔细检查它想要运行的命令,请在这样的echo之前添加一个kill

lsof -i tcp:22 | grep LISTEN | awk '{print }' | xargs echo kill

It'll then list the PIDs that it would ordinarily kill

然后它会列出它通常会杀死的 PID

回答by Chaos

Have you tried using tcpkill?

您是否尝试过使用 tcpkill?

example:

例子:

tcpkill -i eth0 port 21

回答by alain.janinm

I often get this problem using JBoss in Netbeans...

我经常在 Netbeans 中使用 JBoss 遇到这个问题......

My solution :

我的解决方案:

In a terminal type :

在终端类型中:

 sudo netstat -lnp | grep 8080  

Then it display something like:

然后它显示如下:

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

Then use:

然后使用:

 kill 1722  //replace 1722 by the PID you found.

Hope it will help!

希望它会有所帮助!

回答by Xander

fuser -k 16969/tcp

定影器-k 16969/tcp

can free that port. This is a useful command that can be used to close ports. which ever it is. Regards

可以释放那个端口。这是一个有用的命令,可用于关闭端口。无论是什么。问候