Construct kill command

Running Oracle under Solaris 9.  After i shutdown Oracle, sometimes there are still processes running in the ORACLE_HOME such as java or perl.  I need a command that would run sort of like a ps -fu oracle.  Then pipe that to a grep for a /u01/app/oracle.  If it found that line, take the process id and issue a kill -9 for that process id.
xoxomosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amit_gCommented:
ps -fu oracle | grep /u01/app/oracle | grep -v grep | grep -v PID | tr -s " " | cut -d " " -f3 | xargs kill -9

OR

ps -u oracle | grep /u01/app/oracle | grep -v grep | grep -v PID | sed 's/^ *//' | cut -d" " -f1 | xargs kill -9

Check the output of ps -fu oracle and ps -u oracle and make adjustment to -f3 and -f1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yuzhCommented:
You can simply do:

kill -9 `ps -fu oracle -o pid,args | grep /u01/app/oracle | awk '{print $1}'`
TintinCommented:
Do you really need to do a kill -9?
Are there other Oracle processes when you shut it down that you need to keep running?
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

NukfrorCommented:
Two thoughts:

1) I agree with Tintin, kill -9 is sloppy and should only be used when necessary.

2) Anything wrong with using pgrep and pkill ???
TintinCommented:
My second question was to find out whether pgrep and pkill would be appropriate.
xoxomosAuthor Commented:
The backup itself runs under oracle.  Thanks, i didn't think about that.
But they would not be running under /u01/app/oracle. (ORACLE_HOME).  They'd run under /sysadmin/oracle (HOME),
Still now that i hear kill -9 is 'sloppy', how does this other work?
xoxomosAuthor Commented:
let me close this one and post that as seperate question.
TintinCommented:
kill -9 should only be used as a last resort for processes that don't die nicely.

Doing a standard kill (which is actually kill -15), gives the process a chance to clean itself up nicely (assuming it has been written with properly signal handling).  Using kill -9 means kill the process immediately.
NukfrorCommented:
I usually use the analogy of:

A kill -9 is like cutting a chicken's head off.  You don't know if the chicken will die gracefully or spray blood all over the place while the body runs aimlessly around your kitchen making a general mess of things.
TintinCommented:
Nukfror.

I love that analogy!
yuzhCommented:
me too !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.