-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstop_games.sh
executable file
·37 lines (32 loc) · 1001 Bytes
/
stop_games.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# List of ports
ports=(
5001 # Games
)
# Loop through each port
for port in "${ports[@]}"; do
# Find the PID of the process using the port
pids=$(lsof -t -i :$port)
# Check if any PID is found
if [ -z "$pids" ]; then
echo "No process found using port $port"
else
# Loop through each PID and kill it
for pid in $pids; do
echo "Killing process $pid using port $port"
kill $pid
# Verify if the process has been killed
if kill -0 $pid > /dev/null 2>&1; then
echo "Process $pid is still running. Forcing termination..."
kill -9 $pid
if [ $? -eq 0 ]; then
echo "Process $pid has been forcefully terminated."
else
echo "Failed to terminate process $pid."
fi
else
echo "Process $pid has been terminated."
fi
done
fi
done