您的位置 首页 shell脚本

shell 脚本,根据端口 杀死进程

kill_port.sh

#!/bin/bash

# 检查是否提供了端口号
if [ -z "$1" ]; then
  echo "Usage: $0 <port>"
  exit 1
fi

PORT=$1

# 查找占用指定端口的进程
PIDS=$(sudo lsof -t -i :$PORT)

if [ -z "$PIDS" ]; then
  echo "No processes found using port $PORT"
  exit 0
fi

# 终止每个进程
for PID in $PIDS; do
  echo "Killing process with PID $PID"
  sudo kill -9 $PID
done

echo "All processes using port $PORT have been terminated."

 

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章