Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I kill a process running with in multiple sessions using a bash or powershell script?

share|improve this question
6  
your question and your body state different things, please elaborate your question –  freethinker May 19 '11 at 9:51
add comment

3 Answers

Are you looking to automate this, or just to have a tool available where you can manually kill multiple instances of a process by name, regardless of what user session any instance is running in? I'm assuming the latter, and the following should accomplish that.

On Windows, you can't beat Sysinternals' "pskill" utility. Get the SysInternals suite, unpack, and at a command prompt simply use pskill theprocessname to deep-six all instances of the corresponding executable.

The following bash script would provide similar functionality on Linux; I'll leave it to the user to figure out how to loop it until no more instances exist:

#!/bin/bash
if [ $1 -eq ""]; then
echo "Usage : ./pkill.sh <process name>"
else
get_proc=`ps -e -o pid,command | grep $1`
echo $get_proc > get_it
get_pid=`gawk -F" " '{ print $1 }' get_it`
kill -9 $get_pid
fi

(Script lifted directly from http://www.linuxweblog.com/kill-process-name, but pasting it here for posterity because I hate finding dead links in answers on StackExchange sites.)

Hope this helps!

share|improve this answer
add comment

On Windows-machines with powershell installed, you can just do this:

get-process PROCESS_NAME | stop-process

share|improve this answer
add comment

Bash alternative

pgrep killus | while read p; do kill -9 $p; done

kills all processes named killus

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.