Killall script?

I am doing some system tuning and figuring out how to write a script that will kill multiple processes or all processes with the same owner. Can someone help me out? Thanks

What shell are you using?

This is a simple enough script to write. See man ps for how to get the process ID. After that, simply loop through the process ID's and kill them ( man kill )assuming you are root (you are not going to be able to kill them otherwise).

hmm yea i understand how to get the PIDs and use the kill command, but im not quite sure how to incorporate this into a script

Not anywhere near a terminal so this is not at all tested. Also, cant remember off hand which field the PID is so you need to adjust the awk statement accordingly. Run the shell by passing in the user id of the user.

USER=$1

PROCESS_ID=`ps -e | grep ${USER} | awk -F" " '{print $1}'  2> /dev/null`

for ID in $PROCESS_ID
do
  kill -9 $ID
   
  if [ $? -ne 0 ]
   then
     echo "Failed to Kill Process with PID = [ $ID ]"
  fi
done

you could also try from the command line ...

kill -9 `ps -ef | awk '/$user/ && !/awk/ {print $2}'`

or

kill -9 `ps -fu $USER | awk '{print $2}'`