Created
July 30, 2025 23:13
-
-
Save EvilJordan/ef8135a37b82a79a6e9dab1c5e5d9198 to your computer and use it in GitHub Desktop.
MURDER (kill all processes sharing a common name passed as a CLI parameter)
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 | |
| murder() { | |
| if [[ -z $1 ]]; then | |
| echo "Missing argument!" | |
| return | |
| fi | |
| echo "Killing $1..." | |
| PROCESSES=`ps -ax | grep $1 | grep -v grep` | |
| if [[ -z $PROCESSES ]]; then | |
| echo "Nothing to kill!" | |
| return | |
| fi | |
| PROCESSESARRAY=() | |
| while IFS= read -r line; do | |
| PROCESSESARRAY+=("$line") | |
| done <<<"$PROCESSES" | |
| for PROCESS in "${PROCESSESARRAY[@]}"; do | |
| THISPID=`echo $PROCESS | grep -oEm 1 "^[0-9]+"` | |
| echo "Killing PID: $THISPID" | |
| sudo kill $THISPID | |
| done | |
| echo "done." | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment