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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

killing a process

Status
Not open for further replies.

tomdagliusa

Programmer
May 31, 2000
34
US
My dept. does a bad job of cleaning up old processes.
I would like to be able to su to root, and identify the processes, then kill them. I can identify them ok, but how do I access the process number which I need to send to the kill command? Let's say I pipe a ps auxw | grep "someTerm" into a file. The second column in that file are all the process numbers. I'd love to be able to do something like:

for column2 in `ps auxw | grep "someTerm"`
do
kill -9 $column2
done

BUT, don't know how to get that process id into a shell available variable.

Thanks,
Tom
 
`ps auxw|grep "someterm"| awk '{print $2}'`

Where $2 is the pid in the second column


I love deadlines. I like the whooshing sound they make as they fly by.

Douglas Adams
 
# pids=`ps -aux | grep tty | awk '{if ($11 != "grep") print $2}'`
# kill $pids

In this way it will not print the PID for the "grep someterm" process you just typed.
 
FYI. Doug is the name of the guy whose quote I use in my signature.

Ken ;-)


I love deadlines. I like the whooshing sound they make as they fly by.

Douglas Adams
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top