Last active
November 23, 2016 07:02
-
-
Save piaoger/233accafc1d5ce3567bb34d79fd31f39 to your computer and use it in GitHub Desktop.
kill processes by name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
appname=python | |
getpids() { | |
local pids=$(ps -ef | grep $1 | grep -v grep| awk '{print $2}') | |
echo $pids | |
} | |
pids=`getpids $appname` | |
# kill all apps all in one | |
if [ -n "$pids" ] ; then | |
kill -9 $pids | |
fi | |
# Or you can kill app one by one | |
kill_app() { | |
local apppid=$1 | |
#if app_pid exists, kill the process | |
if [ -n "$appid" ] ; then | |
kill -9 $appid | |
sleep 1 | |
fi | |
} | |
for appid in $pids; | |
do | |
echo "PID=$appid" | |
kill_app $appid | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment