Last active
February 14, 2024 21:46
-
-
Save richhh7g/37ad9d1bb1e5dda668e3b06b97f3c4aa to your computer and use it in GitHub Desktop.
Shell - Kill process
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
#!/bin/bash | |
port=3000 | |
if [ $# -gt 0 ]; then | |
port=$1 | |
fi | |
process_pid=$(lsof -i :$port | grep "LISTEN" | awk '{print $2}') | |
if [ -n "$process_pid" ]; then | |
echo "Process PID found on port $port: $process_pid" | |
kill -9 "$process_pid" | |
echo "Process killed successfully." | |
else | |
echo "No process running on port $port." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment