如何在 bash 中结合“lsof -i :port”和“kill pid”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33101725/
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
How to combine "lsof -i :port" and "kill pid" in bash
提问by Oliver
How do i combine these two commands in the bash:
我如何在 bash 中组合这两个命令:
lsof -i :port
kill pid
The first one returns the PID i want to kill to release the port. The second one kills the returned PID.
第一个返回我想杀死以释放端口的PID。第二个杀死返回的PID。
I am doing this because I don′t know of any way to kill a jetty webserver within the Netbeans IDE on OSX. Is there a way?
我这样做是因为我不知道有什么方法可以在 OSX 上的 Netbeans IDE 中杀死一个码头网络服务器。有办法吗?
回答by Eugene Soldatov
You can use $():
您可以使用 $():
kill $(lsof -t -i:port)
回答by El Fadel Anas
You can use
您可以使用
kill -9 `lsof -t -i:port`