windows
netstat -ano | grep 8080
taskkill /pid 1032 -f
或者(批量杀死,主要是findstr,先查找,可以先 netstat -ano 看一下)
netstat -ano | findstr /c:"0.0.0.0:80 "|awk -F" " '{print $5}'|xargs taskkill -f -PID
80后面有空格
/c:后面没有空格
findstr是根据正则表达式查找,需要查找包含空格的文字,否则容易查询8001这种两个的端口
linux
ps -ef | grep 【pidname】 | grep -v grep | awk '{print $2}' | xargs kill -9
或者
pkill -9 redis
#!/bin/bash
PID=$(lsof -i :8013| grep -m 1 "LISTEN" | awk '{print $2}')
if [ -z "$PID" ]; then
echo "PID is empty"
else
kill $PID
fi
参考博客:
findstr 字符串查找增强:findstr_郁闷阳光的博客-CSDN博客_findstr 查找多个字符串是中文
netstat windows下杀死进程 cmd怎么杀死进程-百度经验