Operating System - HP-UX
1833144 Members
3252 Online
110051 Solutions
New Discussion

Re: Kill multiple users processes simultaneously

 
Patriot_3
New Member

Kill multiple users processes simultaneously

I have times when I need to kill a users processes because their workstation may have lockup up or whatever. Is there a way, maybe a script that will kill all their processes at once? Thanks in advance.

PS I am new to HP-UX
12 REPLIES 12
James Beamish-White
Trusted Contributor

Re: Kill multiple users processes simultaneously

All a users processes? Nasty! But this should work:

kill `ps -ef | grep posapp | awk '{print $2}'`

...but I hold no responsibility of harming your system due to this :-)

Cheers,
James
GARDENOFEDEN> create light
Pete Randall
Outstanding Contributor

Re: Kill multiple users processes simultaneously

Please see attached.

Pete

Pete
Pete Randall
Outstanding Contributor

Re: Kill multiple users processes simultaneously

And I echo James' caveats.

Pete

Pete
Patriot_3
New Member

Re: Kill multiple users processes simultaneously

I am wanting to kill a single user's processes, not everyone's. Sorry for the type "o".
Pete Randall
Outstanding Contributor

Re: Kill multiple users processes simultaneously

That's what my attachment does.

Pete

Pete
Nick Wickens
Respected Contributor

Re: Kill multiple users processes simultaneously

You could try this (where dxb is the userid example) -

for PID in $(ps -fudxb|tr -s " "|grep -v UID|cut -d" " -f3)
do
kill $PID
done

Hats ? We don't need no stinkin' hats !!
Nick Wickens
Respected Contributor

Re: Kill multiple users processes simultaneously

Oh by the way you have to make allowances in my suggestion if any of your userids use a full userid field - mine are all three chars long so its field two of the ps -fu output for me. It should be easy enough to lose the leading blank if any though.
Hats ? We don't need no stinkin' hats !!
Shannon Petry
Honored Contributor

Re: Kill multiple users processes simultaneously

#!/bin/sh
echo "Enter the user to dump"
read DUMPEE
CHECK=`grep ^$DUMPEE /etc/passwd|awk -F: '{print $1}'`
if [ ${CHECK}x = x ] ; then
echo "NO SUCH USER"
exit
else
#fall through
PIDLIST=/tmp/pidlist
if [ -f $PIDLIST ] ; then
rm -f $PIDLIST
fi
touch $PIDLIST
ps -ef | grep $DUMPEE|awk '{print $2}' >>$PIDLIST
for PID in `cat $PIDLIST` ; do
kill $PID
done
fi

Now, cuz i have all production machines at the site Im at, this is not tested. Dont complain if it kills your system like you think it should.

If you notice there are several key commands in the examples other than kill which you should get familiar with to fix things like this yerself in the future as well as scripting syntax given by others as well as myself. I'd recommend you get some books like "UNIX System Administration", "Unix in a Nutshell", and something on either the Korn or Borne shell published by O'Reilly and Associates

Regards,
Shannon
Microsoft. When do you want a virus today?
Misa
Frequent Advisor

Re: Kill multiple users processes simultaneously

Here's my offering. It won't let root's processes be killed.

Usage:

twep username

The output is a little ugly (sorry, been lazy) but it gets the job done and I've never noticed it behaving wrong.

The name comes from the old BSD manual pages -- the 9 signal was "terminate with extreme prejudice." I suppose it's not politically correct any more... :(

--Misa
Nick Wickens
Respected Contributor

Re: Kill multiple users processes simultaneously

If you want to kill processes specific to a certain user in a script with a grep from the ps command then "ps -fu" is better to use than ps -ef.

If you are not carefull you could end up killing other processes as well - For example if you had a user called "paul" and an other user "paula" a grep for paul from ps -ef will call up paula as well. Likewise a grep for Paul will also pull up "bigpaul" if you have a user called bigpaul.

You can get around this by putting spaces around your grep ie grep " paul " or by using "^" etc but "ps -fupaul" will only pull up processes for paul.
Hats ? We don't need no stinkin' hats !!
Shannon Petry
Honored Contributor

Re: Kill multiple users processes simultaneously

Did anything here help you fix your problem?
If so, why not take the 30 seconds from your day to assign points to people who took longer than that to answer your request for help?
If not then what is missing from the responses to help you solve your problem?

Regards,
Shannon
Microsoft. When do you want a virus today?
Tom Spence_1
Regular Advisor

Re: Kill multiple users processes simultaneously

Or a simple way to do:

kill -9 `ps -fu [username] | grep -v "PID" | awk '{print $2}'`

Hope it helps.

-Tom
Thinking Snow!