使用BASH如何杀死TCP端口16969? [英] Using BASH how can i kill TCP port 16969?

查看:84
本文介绍了使用BASH如何杀死TCP端口16969?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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?

$ 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?

推荐答案

我认为:

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

应该做到这一点.

要在松散之前仔细检查它想运行什么命令,请在kill之前添加一个echo,如下所示:

To double check what commands it wants to run before letting it loose add an echo before the kill like this:

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

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

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

这篇关于使用BASH如何杀死TCP端口16969?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆