Skip to content

Instantly share code, notes, and snippets.

@ozzieperez
Last active August 27, 2016 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozzieperez/dcf9d901511177d16e8c80998277c03c to your computer and use it in GitHub Desktop.
Save ozzieperez/dcf9d901511177d16e8c80998277c03c to your computer and use it in GitHub Desktop.
Kill a comma-delimited list of processes
#!/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