0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

(調査中)Linux。特定のポートのプロセスを取得して終了

Posted at
#!/bin/bash

PORT=$1

if [ -z "$PORT" ]; then
    echo "Usage: $0 <port>"
    exit 1
fi

# ポートを使用しているPIDを取得
PID=$(sudo lsof -t -i :$PORT)

if [ -z "$PID" ]; then
    echo "No process is using port $PORT."
    exit 0
fi

# プロセスをkill
echo "Killing process $PID using port $PORT..."
sudo kill -9 $PID

if [ $? -eq 0 ]; then
    echo "Process $PID killed successfully."
else
    echo "Failed to kill process $PID."
fi

使用方法
スクリプトを kill_by_port.sh として保存。
実行権限を付与:

chmod +x kill_by_port.sh

実行:

./kill_by_port.sh <ポート番号>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?