1819931 Members
3129 Online
109607 Solutions
New Discussion юеВ

KILL PROCESS

 
Adrian_72
Advisor

KILL PROCESS

HI,
I need make a shell for kill two process for PID in my system but i dont know if the command awk is possible.
Do you have any example for this

May you help me?

Thank you
3 REPLIES 3
Geoff Wild
Honored Contributor

Re: KILL PROCESS

Yes...

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


Or use UNIX95:

http://www.interex.org/pubcontent/enterprise/nov01/qabh1101.jsp

Bill's Q&A from Interex...near the bottom is a script...

Rgds..Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Biswajit Tripathy
Honored Contributor

Re: KILL PROCESS

One problem with:

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

is, this will kill all processes that has the word
"process" in it's "ps -ef" output. This means, if you
are trying to kill a process named "roo", you will end
of killing all the root processes :-)

A better solution is:

# kill $(ps -e | grep " process$" | awk '{print $1}')

Note the black space in " process$" search string.

- Biswajit
:-)
Bill Hassell
Honored Contributor

Re: KILL PROCESS

Actually, there is no better solution than to let ps find your processes by name. ps and grep is a very unstable way to locate processes by name because grep does not know where the process name is located and does a simple string match. The UNIX95 option will not only enable the -C option but also allow you to show just the fields you need for your script.

But we need additional information. Do you know the names of the two processes? Are these names the same or different? Will there always be exactly two of these processes or will there be one or many more?


Bill Hassell, sysadmin