-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Major
committed
Aug 7, 2024
1 parent
0132f01
commit c083ac6
Showing
17 changed files
with
879 additions
and
514 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
|
||
# Function to kill processes by port | ||
kill_processes_by_port() { | ||
local port=$1 | ||
local pids=$(lsof -t -i:$port) | ||
|
||
if [ -z "$pids" ]; then | ||
echo "No processes found running on port $port." | ||
return | ||
fi | ||
|
||
echo "Found processes running on port $port: $pids" | ||
|
||
echo "Sending SIGTERM to processes..." | ||
for pid in $pids; do | ||
sudo kill -TERM $pid | ||
done | ||
|
||
# Wait for a moment to ensure processes receive the signal | ||
sleep 2 | ||
|
||
echo "Sending SIGKILL to processes..." | ||
for pid in $pids; do | ||
sudo kill -KILL $pid | ||
done | ||
|
||
# Wait for a moment to ensure processes are killed | ||
sleep 2 | ||
|
||
echo "Using fuser to release port $port..." | ||
sudo fuser -k $port/tcp | ||
|
||
# Verify if any processes are still running on the port | ||
remaining_pids=$(lsof -t -i:$port) | ||
if [ -z "$remaining_pids" ]; then | ||
echo "All processes on port $port have been terminated." | ||
else | ||
echo "Processes still running on port $port: $remaining_pids" | ||
echo "Attempting to kill remaining processes with SIGKILL..." | ||
for pid in $remaining_pids; do | ||
sudo kill -KILL $pid | ||
done | ||
fi | ||
|
||
# Final check | ||
final_pids=$(lsof -t -i:$port) | ||
if [ -z "$final_pids" ]; then | ||
echo "All processes on port $port have been terminated." | ||
else | ||
echo "Failed to terminate processes: $final_pids" | ||
fi | ||
} | ||
|
||
# Check if a port is provided | ||
if [ -z "$1" ]; then | ||
echo "Usage: $0 <port>" | ||
exit 1 | ||
fi | ||
|
||
# Run the function to kill processes on the specified port | ||
kill_processes_by_port $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.