Operating System - HP-UX
1838662 Members
9224 Online
110128 Solutions
New Discussion

Kill the Process dynamically

 
SOLVED
Go to solution
UVA
Regular Advisor

Kill the Process dynamically

Hi Unix Gurus,

I have sapdisp application, unfortunately this application doesnt have the utility to stop the application, every time i need to kill the process to stop this.

So i need to make a script which can filter the PID of this application and kill the process dynamically.

Please can any one help me on this....
4 REPLIES 4
Ivan Krastev
Honored Contributor

Re: Kill the Process dynamically

Use ps:

$ ps -ef | grep -v grep | grep syslog | awk '{print $2}'
963
$ ps -ef | grep 963
root 963 1 0 Dec 3 ? 0:25 /usr/sbin/syslogd -D


regards,
ivan
Rasheed Tamton
Honored Contributor
Solution

Re: Kill the Process dynamically

Hi,

ps -ef|awk '/sapdispdaemon/{ print "kill ",$2 }'|sh

with -9:

ps -ef|awk '/sapdispdaemon/{ print "kill -9",$2 }'|sh


rgds.
Dennis Handly
Acclaimed Contributor

Re: Kill the Process dynamically

You can use this to find and kill the process:
kill $(UNIX95=1 ps -C sapdispdaemon -opid=)

You should test it first by adding an echo and then: ps -fp the-pid
James R. Ferguson
Acclaimed Contributor

Re: Kill the Process dynamically

Hi:

As Dennis suggests, use the UNIX95 (XPG) behavior of 'ps' with '-C' to find the process you want.

Finding a process with 'grep' can lead to false positives. Using 'ps -C ' matches to the process's basename and is guaranteed not to yield false matches.

Too, do NOT use 'kill -9' except as a very last resort. A 'kill -9' can't be caught and hence your process will have no chance to cleanup temporary files and/or shared memory.

Start with a 'kill -hup' then a 'kill -term' [the default] and then only as a last resort issue a 'kill -9'.

Regards!

...JRF...