Last active
August 27, 2016 08:31
-
-
Save ozzieperez/dcf9d901511177d16e8c80998277c03c to your computer and use it in GitHub Desktop.
Kill a comma-delimited list of processes
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 | |
# ex: ./killprocs.sh Process1,Process2,Process3 | |
# set the "internal field separator" variable (delimiter) | |
IFS=',' | |
# read the delimited line into an array | |
read -ra PROCS <<< "$1" | |
# loop through the array | |
for i in "${PROCS[@]}"; do | |
# get the PID of the process | |
id=$(ps -Ac | grep -i $i | head -1 | awk '{print $1;}') | |
if [ -n "$id" ] | |
then | |
echo "About to kill" $i "with process PID:" $id | |
#kill the process | |
sudo kill -9 $id | |
else | |
echo "Couldn't find:" $i | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment