1834247 Members
2453 Online
110066 Solutions
New Discussion

Re: KIll Process

 
Dave Elliott
Frequent Advisor

KIll Process

Hi guys.
I know that someone out there will know an easy way to cure my problem.
i need to kill a specific process ate shutdown level2 i am trying to use
"ps -ef | grep (process name) | cut ( to select pid) | kill -9"
to remove said process although there may be an easier way.
can anyone help and tell me the best command string to use to select the process and kill it, i am going to put this script at run level 2.
regards
andy
Oracle DBA
7 REPLIES 7
Pete Randall
Outstanding Contributor

Re: KIll Process

Andy,

Here's a good thread about process killing:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xc8d7a135f587d5118ff00090279cd0f9,00.html

HTH,
Pete

Pete
Stefan Farrelly
Honored Contributor

Re: KIll Process


Using ps then cut is a normal way to do it, only one thing to remember, use grep -v grep in the command or else you may end up only killing your grep (process name) pid, not the real pid you wanted to kill !

Im from Palmerston North, New Zealand, but somehow ended up in London...
Bill Thorsteinson
Honored Contributor

Re: KIll Process

I script my startup to save the PID to a file. Then I can
kill the process with a simple
command:

kill -KILL $(cat process.pid)


I use the following function which is cleaner.

kill_job () {
pid=`cat ${pid_file}`
if [ -f ${pid_file} ]; then
if ps -p ${pid} > /dev/null; then
kill -KILL ${pid}
fi
rm -f ${pid_file}
fi
}


The pidfile is create with

echo $! > ${pid_file}

executed immediately after the command is run.
Allan Pincus
Frequent Advisor

Re: KIll Process

Is this process started at boot time and set up using the rcXX.d files, rc.config.d? If so, you will probably want to stop the process "cleanly" using:

/sbin/init.d/processName stop

Command and use a process number linked to a KILL script in rc2.d

Unless you know exactly what this script does.

Without knowing the details, using the kill -9 described above might leave some things floating around your system.
Ray Brewer
Valued Contributor

Re: KIll Process

This works for me:
kill -9 $(ps -ef | grep | grep -v grep | awk '{print $2}')

Ray
Martin Johnson
Honored Contributor

Re: KIll Process

I would caution against using -9. This automatically terminates the process without any cleanup. This means buffers don't get flushed. Shared memory segments don't get released, etc.

I would use, in the following order:

-15 (terminate)
-1 (hangup)
-3 (quit)
and as a last resort -9 (kill)

HTH
Marty
Ray Brewer
Valued Contributor

Re: KIll Process

Sorry about the "kill -9" in my previous reply. This should be substituted for the appropriate level you require.