Skip to content

Instantly share code, notes, and snippets.

@Venkat2811
Created December 28, 2016 06:56
Show Gist options
  • Select an option

  • Save Venkat2811/ecfc9b1e7bd22506494a3070a2c50b9d to your computer and use it in GitHub Desktop.

Select an option

Save Venkat2811/ecfc9b1e7bd22506494a3070a2c50b9d to your computer and use it in GitHub Desktop.
Shell script to grep and kill all process by name. Usage `sudo ./kill_all_processes_by_name.sh process_name`
#!/bin/bash
i="1"
echo "Running Script to kill all $1 processes"
while [[ $i -lt 100 ]]; do
PID=`ps -ef | grep $1 | grep -v 'grep' | awk '{print $2}'`
if [[ "" != "$PID" ]]; then
echo "killing $PID"
kill -9 $PID
fi
i=$(( $i + 1 ))
done
echo "Done.."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment