Skip to content

Instantly share code, notes, and snippets.

@bc-jasond
Last active April 26, 2016 17:01
Show Gist options
  • Select an option

  • Save bc-jasond/796dfb6d3bb71da4bb27 to your computer and use it in GitHub Desktop.

Select an option

Save bc-jasond/796dfb6d3bb71da4bb27 to your computer and use it in GitHub Desktop.
kill all processes named argv[1] or at prompt
#!/usr/bin/env bash
if [ -z "$1" ]
then
echo "What should I kill?"
read line
else
line="$1"
fi
arr=($(sudo ps -A | grep "$line" | cut -d' ' -f1))
for i in "${arr[@]}"; do
echo "killing process: $i"
sudo kill -9 $i
done
arr=($(sudo ps -A | grep "$line" | cut -d' ' -f2))
for i in "${arr[@]}"; do
echo "killing process: $i"
sudo kill -9 $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment