ipzig
December 16, 2007, 2:25am
1
Hi,
I know that the answer to this is very simple, since I saw somebody do it some time back..but I forgot how.
The problem is, I have multiple instances of the same program running simultaneously and I want to kill them all in a single command.
I know that it can be done using awk '{print $2}' in combination with ps and kill but I am not able to formulate the exact command.
The process in question (to be killed) is xterm.
will deeply appreciated all help.
ipzig
porter
December 16, 2007, 2:52am
2
if you have pkill it is a doddle....
pkill xterm
Will pkill kill only the instance that a user has permission to kill ?
user A can run the instance proc p1
and user B can also run the same instance proc p1
will pkill identify only the instances from user A and kill only those instances of proc p1
( may be something like ps -fu $user )
porter
December 16, 2007, 3:33am
4
It can't kill the ones you don't.
Well, that is true.
Am interested to know whether it would skip it as such or will throw an error stating unable to kill the other instance.
I will check that !
ipzig
December 16, 2007, 11:37am
6
I don't have pkill.
Yet, I know the answers a doddle if you can combine kill, ps -fu, and awk '{print $2}' (with ps).
Only, am not able to do it myself, and waiting for a shell expert to do it for me..
Regards
ipzig
As long as you know the name of the process take a look at the 'killall' command.
try this
kill `ps -ef |awk '/xterm/ && !/'$$'/' | awk '{print $2}'`
system
December 16, 2007, 1:52pm
9
ps aux | grep $1 | awk '{system("kill " $2);}'
I put this in a script named KillAll, then call the script with the string I want to filter for. But, be careful, it doesn't care where it finds your search string, it will kill anything with the string anywhere in the results of ps aux. The script could be easily improved.
-Jmt
This may work
kill `ps -ef |awk '/xterm/ && !/'$$'/' | awk '{print $2}'`
ipzig
December 17, 2007, 12:25am
11
JMT and Kundunni,
thank you both a lot for your replies. I'll try your solutions as soon as I get to my work.
I am sure JMT's solution will work since I understand what his command exactly does.
But kundunni, I'd highly appreciate it if you explain your command.
BTW, seeing your posts.. I'm thinking is this:
kill -9 `ps -fu | grep "xterm" | awk '{print $2}'`
would work?
awaiting your reply.
Regards
Indrajit
In ksh:
ps -eaf | grep xterm | grep -v grep | while read a b c ; do
kill $b
done
Don't you have to specify the username along with ps -fu ?
ps -fu $USER