Created
February 15, 2024 12:20
-
-
Save Minozzzi/aa61b151b5b660c740e0de62c34684b0 to your computer and use it in GitHub Desktop.
Shell script to terminate processes on ports
This file contains hidden or 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
#!/bin/bash | |
if [ $# -ne 1 ]; then | |
echo "Uso: $0 PORTA" | |
exit 1 | |
fi | |
PORTA=$1 | |
PIDS=$(sudo lsof -t -i:$PORTA) | |
if [ -z "$PIDS" ]; then | |
echo "Nenhum processo escutando na porta $PORTA" | |
else | |
for PID in $PIDS; do | |
sudo kill -9 $PID | |
echo "Processo com PID $PID na porta $PORTA morto com sucesso" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment