Killing spicified Uer Process Linux
Posted by Simson on April 20th, 2009Sometimes you may encounter some user programs or script hogging your Machine performa, this may couse by Bug on the application or exploit, so we may need to do fast killing all his/her process, this can be done by folowing script, safe it on your /usr/local/bin/kill-user
#!/bin/bash
USER=$1
USERNAAM=`basename $0`
if [ ! -n "$USER" ]
then
echo "Usage: $USERNAAM username" >&2
exit 1
elif ! egrep "^$USER:" /etc/passwd >/dev/null
then
echo "User $USER does not exist!" >&2
exit 2
fi
PIDS=`ps -U$USER | grep -v PID| awk '{print $1}'`
echo "Killing " `echo $PIDS | wc -w` " processes for user $USER."
for PID in $PIDS
do
kill -9 $PID 2>&1 >/dev/null
done
echo "User $USER has " `ps -U$USER | grep -v PID | wc -l` " processes still running."
after that script has been saved in binary folder then the script must be executable
do this:
root@www:~ # chmod 755 /usr/local/bin/kill-user
In practice:
root@www:~ # kill-user jerry
Killing 10 processes for user jerry.
User jerry has 0 processes still running.


Recent Comments