Skip to content

Instantly share code, notes, and snippets.

@kjbrum
Created August 11, 2015 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kjbrum/ced851437f3fb8190299 to your computer and use it in GitHub Desktop.
Save kjbrum/ced851437f3fb8190299 to your computer and use it in GitHub Desktop.
A small bash script to search and kill processes
#!/bin/bash
if [ -z "$1" ]; then
echo "You need to supply a search string..."
else
processes=$(ps aux | grep $1 -i | awk -F ' ' '{print $2}' | xargs)
echo "Processes: "$processes
while true; do
read -ep "Are you sure you want kill all '$1' processes? [y/N] " yesno
case $yesno in
[Yy]* )
echo 'Killing processes...'
for i in $processes; do kill $i; done
echo "Processes Killed: " $processes
break;;
* )
echo "Skipped killing processes..."
break;;
esac
done
fi
@githubuser00
Copy link

more better:
processes=$(ps aux | grep $1 -i|grep -v grep | awk -F ' ' '{print $2}' | xargs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment