- 根据关键字查找进程ID
# ps aux | grep "python3" | cut -c 9-15
- 根据端口号查找进程ID
方式一
# lsof -i:8099| awk '{print $2}'
方式二
# ss -tnlp | grep ":8099"
LISTEN 0 128 *:8099 *:* users:(("python3",pid=31489,fd=4),("python3",pid=31440,fd=4))
LISTEN 0 128 [::]:8099 [::]:* users:(("python3",pid=31489,fd=5),("python3",pid=31440,fd=5))
方式三
# fuser -v 8099/tcp
USER PID ACCESS COMMAND
8099/tcp: root 31440 F.... python3
root 31489 F.... python3
方式四
# netstat -lnp | grep 8099
- 去掉标题行和重复行
# lsof -i:8099| awk '{if (NR>1){print $2}}' | uniq
- 批量杀进程
方式1:
# lsof -i:8099| awk '{if (NR>1){print "kill -9 "$2}}' | uniq | sh
方式2:
# lsof -i:8099| awk '{if (NR>1){print $2}}' | uniq | xargs kill -9
网友评论