Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Killing multible process in AIX 5.1 1

Status
Not open for further replies.

june54

Technical User
Jun 4, 2003
160
0
0
US
Does anyone know of a way to kill multible processes in AIX5.1 ...

Thanks
 
First the obvious: the "kill" command

Now, assuming you already knew about the command, could you give us more information about what you're wanting to do?

Are you wanting to kill all instances of a certain program?
All programs belonging to a certain user?


Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
All instance of a of a certain program
 
Does the program not have it's own method of killing processes, and if not why not (lazy programming?)? This is usually cleaner than using kill willy-nilly.
 
These are SAP generated processes for a particular instance ..
 
You'll probably need to write a script to handle that, and you'd better be very, very, careful with it. I have a personal aversion to automated killing of processes, because there's a good risk of "becoming famous", something no sys admin ever wants to do. To paraphrase Roger "Verbal" Kint (aka Keyser Soze): "The greatest trick a sys admin ever pulls is convincing his users that he doesn't exist." (s/his/her/g as needed)

Another possibility, if all of the processes access a common file (and no others do), would be to use the "fuser -k" command.

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Thanks I had a feeling that would be the case ..

Thanks for your help and have a great day !!!!!!!!
 
june54,

Are they all in the same program group?

ps -ef -o pid,pgid,comm | grep <command>

to see if all <command> instances have the same pgid, then:

ps -ef -o pid,pgid,comm | grep <pgid found in step one>

to see if there are other processes you wouldn't want to kill in that group.

If killing the whole program group will work, then you can use the kill command in the following form. For this example, we'll kill (actually send interrupt signals to) all programs in program group 12345 with a SIGTERM (15) signal:

kill -15 -12345

SIGTERM is the default signal used by kill when you do a simple "kill <pid>". When killing a program group, the signal must be explicitly listed, or the group id will be interpreted as an invalid signal and no pid.



Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
To kill multiple processes:

kill -9 `ps -ef | grep <value> | grep -v grep | awk '{print $2}'`

or

junk=$(ps -ef | grep <value> | grep -v grep | awk '{print $2}'); kill -9 $junk

obviously, the first one is shorter, but you can view the output with the second one before using kill.
 
Here's a little trick for keeping the grep from showing up when you're grepping ps output.

Let's say we're looking for aixterm.

ps -ef | grep [a]ixterm



Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
In response to Rod's.....

or

ps -ef | grep aixterm | grep -v grep


Probably not as clean as rods, but it works
 
When I was growing up, we couldn't afford to throw pipes and processes around like that. [tongue]

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
since rod started this... you are using awk anyway in this line:

junk=$(ps -ef | grep <value> | grep -v grep | awk '{print $2}'); kill -9 $junk

so to avoid spawning unnecessary processes and using a few precious bytes of RAM:

ps -ef|awk '/<value>/{system("kill -9 "$2)}'

if <value> is something in a particular column, say a PPID, you can also do this:

ps -ef|awk '$2~/<value>/{system("kill -9 "$1)}'

that would kill off the children of <value>. you can pass <value> into awk as a variable, also.

IBM Certified -- AIX 4.3 Obfuscation
 
i see, RodKnowlton excepted, nobody discovered the 'new' ps.
tell 'ps' to present you the output you need.
stop this, since s5r4 (ca 1995) obsolete, grep|awk carnival.
try, just for fun
(don't forget the SPACE in front of the 2nd / )
ps -efoargs,pid|sed -ne "s/.*WHAT-YOU-WANT.* //p"

don't forget, RTFMP :) guggach
 
forgot the killing part on the end. =)

IBM Certified -- AIX 4.3 Obfuscation
 
I just use `ps -ef |grep <value> |grep -v grep | awk '{print $2}' |xargs kill`
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top