Operating System - HP-UX
1834431 Members
2081 Online
110067 Solutions
New Discussion

In Single Command "How to kill the particular user process"

 
Saraswathy_1
Advisor

In Single Command "How to kill the particular user process"

Hey can any one help me in killing user process in single command.
An application user owns 50 process if one process is hung I have to kill all the processes manually so 50 times I need to use kill command.

I wanted to avoid this tedious job.
5 REPLIES 5
baiju_3
Esteemed Contributor

Re: In Single Command "How to kill the particular user process"


Hi

This shuld work.

ps -fu "username" |awk '{print $2}' |grep -v PID |while read pid ;do
echo "killing $pid"
kill -9 $pid
done


Thanks.
Good things Just Got better (Plz,not stolen from advertisement -:) )
Pete Randall
Outstanding Contributor

Re: In Single Command "How to kill the particular user process"

You need a little script:

PROCESSES=`UNIX95= ps -U $USERNAME | \
grep -v PID |awk '{ print $1 }' | sort -n`
. for PROC in $PROCESSES
. do
. echo "\tKilling process $PROC"
. kill -9 $PROC
. done


Pete

Pete
Muthukumar_5
Honored Contributor

Re: In Single Command "How to kill the particular user process"

You can do it as,

# ps -f | awk '!/COMMAND/ { print $1 }' | xargs kill -9

# ps -f | awk '!/COMMAND/ { print "kill -9 "$1 }' | ksh

# kill -9 `ps -f | awk '!/COMMAND/ { print $1 }'`

hth.
Easy to suggest when don't know about the problem!
Ron Irving
Trusted Contributor

Re: In Single Command "How to kill the particular user process"

If I think waaaay back, I remember that if you run 'who -u', that will give you the login job number. If you kill that one, maybe they all die with it? Le me know.

ron
Should have been an astronaut.
Saraswathy_1
Advisor

Re: In Single Command "How to kill the particular user process"

Thanks to all for instant response.