Saturday, January 3, 2009

kill any application in linux through terminal

Here is a small shell script to kill any application in Linux through terminal. Of course you should have the permission to kill that process.


EXPECTED_ARGS=1
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: appkill.sh [application name]"
exit 0
fi
pid=`ps -el | grep $1 | awk '{print $4}'`
echo $pid
kill -9 $pid

Save it as, say appkill.sh . Now make the file executable using the following command

$> chmod +x appkill.sh

Now one can kill any application by giving its name as an argument to the script

$> appkill.sh applicationname

Example: To kill firefox use

$> appkill.sh firefox