ps -ef | grep -i seamonkey | awk '{print $2}' | xargs kill -9 -
replace seamonkey with the user name / process name or some other info.
Main Topics
Browse All TopicsI have a solution hosted on a Unix HP-UX B.11.11 U 9000/800 system. This program opens several instances of the same process. I am trying to create a batch which filters by process name and pass the pid to be killed.
I tried the below which did not work out for me.
ps -elf | grep | gawk '{print$1}' | xargs kill -9
Can you please update me with another solutions which loops and kill the processes identified by same name but have different PID's.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Or you could use
kill -9 $(ps -ef| grep seamonkey|awk '{print $2}'
As with all of the above, this will try to kill the "grep" command itself, and will throw an error if there are no processes with that name.
To avoid both of these errors, you could use:
PIDS=$(ps -ef | grep '[ ]'seamonkey|awk '{print $2}')
if [ ! -s $PIDS ]
then
kill -9 $PIDS
fi
The '[ ]' in front of the name avoids "grep" matching its own command, and the "if" test stops killing an empty list. The "kill" command kills all of the pids in one go.
The reason for using xargs above is if the list of pids is very long. It would have to be several thousand pids to cause a problem with command-line length.
Use the UNIX95= variant of the ps command.
That will enable you to identify PIDs based on the command executed, without using grep.
I don't have access to a machine to try it out, but it should be something like:
UNIX95= ps -C "process_name" -o pid="" | xargs kill -9
Note: there must be a space character or tab following the equal sign and before the 'ps' command:
Try it without the kill to see the list of PID's are what you expect them to be.
Regards
JJ
Business Accounts
Answer for Membership
by: woolmilkporcPosted on 2009-11-03 at 06:43:51ID: 25729379
ps -elf | grep "string" | awk '{print $1}' | sort | uniq | xargs -I{} echo kill -9 {}
Change "string" to your search criteria.
Please note that I put an echo in front of kill. Remove it when you're sure what you're doing.
wmp