Skip to content

Instantly share code, notes, and snippets.

@shoaibi
Created June 25, 2015 15:33
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 shoaibi/18749d60600fd72af798 to your computer and use it in GitHub Desktop.
Save shoaibi/18749d60600fd72af798 to your computer and use it in GitHub Desktop.
Kill a process by its (partial) name
#!/bin/bash
E_BADARGS=65
if [ $# -ne 2 -a $# -ne 1 ]
then
echo "Usage: $0 {processNameWithoutSpaces} [{signal}]"
exit $E_BADARGS
fi
process_name="$1"
signal="$2"
if [ "x$signal" = "x" ]; then
signal="-9"
fi
sudo ps aux | grep "$process_name" | grep -v "grep $process_name" | awk '{print $2}' | xargs sudo kill "$signal"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment