<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Killing processes automatically. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629039#M237285</link>
    <description>Not a good design at all. kill -9 is the first problem. NEVER use kill -9 until you have tried kill -15 and perhaps kill -1. The reason is that kill -9 prevents the program code from cleaning up open files and logs and releasing shared memory, semaphores and memory mapped files. I would suggest that your script try each kill signal and then issue a warning when resorting to kill -9.&lt;BR /&gt; &lt;BR /&gt;The secon d is ps and grep--a deadly combination. grep doesn't care what it finds on the ps line. The string "weblogic.server" will appear is the ps listing as part of the grep string or it may appear as a parameter given to some program. A worse case is where you grep for weblogic and there are users with that username, there are programs like weblogic.control, etc, all will be found and blindly killed by such a script.&lt;BR /&gt; &lt;BR /&gt;Now true, you are using ps -e rather than -ef which drops the command line arguments, but it is always recommeded to use ps to locate your process by name, not grep. To show you how bad this can be, try these two commands:&lt;BR /&gt; &lt;BR /&gt;ps -ef | grep sh&lt;BR /&gt;UNIX95= ps -C sh&lt;BR /&gt; &lt;BR /&gt;The first will find critical system processes like unhashdaemon (don't kill that one!) while the second only find sh (and not ksh or csh, etc)&lt;BR /&gt;&lt;BR /&gt;Here is a general method where the program name is assigned to a variable, and it exactly located with ps -C (note that -c -H and -o are enhanced ps commands and need the UNIX95 variable temporarily set to activate these options)&lt;BR /&gt; &lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;set -u&lt;BR /&gt;export PATH=/usr/bin&lt;BR /&gt;PROGNAME=sleep&lt;BR /&gt;PROGLIST=$(UNIX95= ps -C $PROGNAME -o pid=)&lt;BR /&gt; &lt;BR /&gt; if [ "$PROGLIST" = "" ]&lt;BR /&gt; then&lt;BR /&gt; echo "\n$PROGNAME not running\n"&lt;BR /&gt; exit 1&lt;BR /&gt; fi&lt;BR /&gt;  &lt;BR /&gt;  for PIDNUM in $PROGLIST&lt;BR /&gt;  do&lt;BR /&gt;  echo "\nKilling PID $PIDNUM:"&lt;BR /&gt;  ps -fp $PIDNUM&lt;BR /&gt;  kill -15 $PIDNUM&lt;BR /&gt;  sleep 1&lt;BR /&gt;  ps -fp $PIDNUM &amp;gt; /dev/null&lt;BR /&gt;  if [ $? -eq 0 ]&lt;BR /&gt;  then&lt;BR /&gt;  kill -1 $PIDNUM&lt;BR /&gt;  sleep 1&lt;BR /&gt;  ps -fp $PIDNUM &amp;gt; /dev/null&lt;BR /&gt;  if [ $? -eq 0 ]&lt;BR /&gt;  then&lt;BR /&gt;  kill -9 $PIDNUM&lt;BR /&gt;  sleep 1&lt;BR /&gt;  echo "(kill -9 $PIDNUM required)&lt;BR /&gt;  ps -fp $PIDNUM &amp;gt; /dev/null&lt;BR /&gt;  if [ $? -eq 0 ]&lt;BR /&gt;  then&lt;BR /&gt;  echo "\nWARNING: $PIDNUM cannot be killed\n"&lt;BR /&gt;  fi&lt;BR /&gt;  fi&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;Now in this example, I've set PROGNAME to "sleep" so you can test it. It will handle zero or more copies of the same program name, first trying to terminate with SIGTERM (-15), then SIGHUP (-1) and finally SIGKILL (-9) with a warning. And if the process is still not dead, it is hung on I/O and can never be killed.</description>
    <pubDate>Mon, 19 Sep 2005 09:36:35 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2005-09-19T09:36:35Z</dc:date>
    <item>
      <title>Killing processes automatically.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629033#M237279</link>
      <description>I want to kill weblogic process through a script.&lt;BR /&gt;&lt;BR /&gt;i use the command &lt;BR /&gt;&lt;BR /&gt;"kill -9 `ps -e |grep weblogic.server |cut -c 3-6`"&lt;BR /&gt;&lt;BR /&gt;But there is chance that the number of digits in the pid may increase and than the script will not work.&lt;BR /&gt;&lt;BR /&gt;Please help&lt;BR /&gt;&lt;BR /&gt;Santosh jha</description>
      <pubDate>Mon, 19 Sep 2005 08:52:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629033#M237279</guid>
      <dc:creator>santosh jha</dc:creator>
      <dc:date>2005-09-19T08:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Killing processes automatically.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629034#M237280</link>
      <description>Hey;&lt;BR /&gt;&lt;BR /&gt;Automatically killing processes is generally a bad idea.  If, for some reason, your script identifies process 1, for instance, your system is history.&lt;BR /&gt;&lt;BR /&gt;That being said:&lt;BR /&gt;&lt;BR /&gt;ps -ef | grep [w]eblogic_serve | awk '{print $2}' | xargs -i kill {}&lt;BR /&gt;&lt;BR /&gt;is the syntax I'd use if I wanted to do something as dangerous...&lt;BR /&gt;&lt;BR /&gt;Doug</description>
      <pubDate>Mon, 19 Sep 2005 08:58:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629034#M237280</guid>
      <dc:creator>Doug O'Leary</dc:creator>
      <dc:date>2005-09-19T08:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Killing processes automatically.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629035#M237281</link>
      <description>Use awk rather than cut:&lt;BR /&gt;&lt;BR /&gt;"kill -9 `ps -e |grep weblogic.server | awk '{ print $2 }'`"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Mon, 19 Sep 2005 08:59:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629035#M237281</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2005-09-19T08:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Killing processes automatically.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629036#M237282</link>
      <description>Thnaks a lot guys .</description>
      <pubDate>Mon, 19 Sep 2005 09:02:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629036#M237282</guid>
      <dc:creator>santosh jha</dc:creator>
      <dc:date>2005-09-19T09:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Killing processes automatically.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629037#M237283</link>
      <description>You can use the following script to kill processes.&lt;BR /&gt;&lt;BR /&gt;Usage:&lt;BR /&gt;killall &lt;PROCESS_NAME&gt;&lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;killall weblogic&lt;BR /&gt;---------------------&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;PS=/usr/bin/ps&lt;BR /&gt;AWK=/usr/bin/awk&lt;BR /&gt;GREP=/usr/bin/grep&lt;BR /&gt;KILL=/usr/bin/kill&lt;BR /&gt;&lt;BR /&gt;if [ $# -ne 1 ]&lt;BR /&gt; then&lt;BR /&gt;    echo Kullanim   :   ./killall   proses_adi&lt;BR /&gt;    exit&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;for pid in `$PS -e | $GREP $1 | $GREP -v grep | $AWK ' { print $1 }'`&lt;BR /&gt;do&lt;BR /&gt;$KILL -9 $pid&lt;BR /&gt;echo $pid  $1  killed&lt;BR /&gt;done&lt;BR /&gt;-------------&lt;/PROCESS_NAME&gt;</description>
      <pubDate>Mon, 19 Sep 2005 09:04:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629037#M237283</guid>
      <dc:creator>Hakan Aribas</dc:creator>
      <dc:date>2005-09-19T09:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Killing processes automatically.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629038#M237284</link>
      <description>Don't use -9 as you can windup leaving zombies and/or shared memory not cleared, etc....&lt;BR /&gt;&lt;BR /&gt;kill -18 is better or just the default (15)...&lt;BR /&gt;&lt;BR /&gt;What I used to do for example - on zombies:&lt;BR /&gt;&lt;BR /&gt;logfile=/tmp/killzombies.log&lt;BR /&gt;if [ -f $logfile ];&lt;BR /&gt;then&lt;BR /&gt;        rm $logfile&lt;BR /&gt;        touch $logfile&lt;BR /&gt;else&lt;BR /&gt;        touch $logfile&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff&lt;BR /&gt;&lt;BR /&gt;for i in `ps -el|grep -v SZ|grep Z|awk '{print $5}'`&lt;BR /&gt;do&lt;BR /&gt;        ps -ef|grep -v grep|grep ${i} &amp;gt;&amp;gt;$logfile 2&amp;gt;&amp;amp;1&lt;BR /&gt;        mailx -s "Check Zombie(s)" me@mydomain.com &amp;lt;$logfile&lt;BR /&gt;</description>
      <pubDate>Mon, 19 Sep 2005 09:05:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629038#M237284</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2005-09-19T09:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Killing processes automatically.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629039#M237285</link>
      <description>Not a good design at all. kill -9 is the first problem. NEVER use kill -9 until you have tried kill -15 and perhaps kill -1. The reason is that kill -9 prevents the program code from cleaning up open files and logs and releasing shared memory, semaphores and memory mapped files. I would suggest that your script try each kill signal and then issue a warning when resorting to kill -9.&lt;BR /&gt; &lt;BR /&gt;The secon d is ps and grep--a deadly combination. grep doesn't care what it finds on the ps line. The string "weblogic.server" will appear is the ps listing as part of the grep string or it may appear as a parameter given to some program. A worse case is where you grep for weblogic and there are users with that username, there are programs like weblogic.control, etc, all will be found and blindly killed by such a script.&lt;BR /&gt; &lt;BR /&gt;Now true, you are using ps -e rather than -ef which drops the command line arguments, but it is always recommeded to use ps to locate your process by name, not grep. To show you how bad this can be, try these two commands:&lt;BR /&gt; &lt;BR /&gt;ps -ef | grep sh&lt;BR /&gt;UNIX95= ps -C sh&lt;BR /&gt; &lt;BR /&gt;The first will find critical system processes like unhashdaemon (don't kill that one!) while the second only find sh (and not ksh or csh, etc)&lt;BR /&gt;&lt;BR /&gt;Here is a general method where the program name is assigned to a variable, and it exactly located with ps -C (note that -c -H and -o are enhanced ps commands and need the UNIX95 variable temporarily set to activate these options)&lt;BR /&gt; &lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;set -u&lt;BR /&gt;export PATH=/usr/bin&lt;BR /&gt;PROGNAME=sleep&lt;BR /&gt;PROGLIST=$(UNIX95= ps -C $PROGNAME -o pid=)&lt;BR /&gt; &lt;BR /&gt; if [ "$PROGLIST" = "" ]&lt;BR /&gt; then&lt;BR /&gt; echo "\n$PROGNAME not running\n"&lt;BR /&gt; exit 1&lt;BR /&gt; fi&lt;BR /&gt;  &lt;BR /&gt;  for PIDNUM in $PROGLIST&lt;BR /&gt;  do&lt;BR /&gt;  echo "\nKilling PID $PIDNUM:"&lt;BR /&gt;  ps -fp $PIDNUM&lt;BR /&gt;  kill -15 $PIDNUM&lt;BR /&gt;  sleep 1&lt;BR /&gt;  ps -fp $PIDNUM &amp;gt; /dev/null&lt;BR /&gt;  if [ $? -eq 0 ]&lt;BR /&gt;  then&lt;BR /&gt;  kill -1 $PIDNUM&lt;BR /&gt;  sleep 1&lt;BR /&gt;  ps -fp $PIDNUM &amp;gt; /dev/null&lt;BR /&gt;  if [ $? -eq 0 ]&lt;BR /&gt;  then&lt;BR /&gt;  kill -9 $PIDNUM&lt;BR /&gt;  sleep 1&lt;BR /&gt;  echo "(kill -9 $PIDNUM required)&lt;BR /&gt;  ps -fp $PIDNUM &amp;gt; /dev/null&lt;BR /&gt;  if [ $? -eq 0 ]&lt;BR /&gt;  then&lt;BR /&gt;  echo "\nWARNING: $PIDNUM cannot be killed\n"&lt;BR /&gt;  fi&lt;BR /&gt;  fi&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;Now in this example, I've set PROGNAME to "sleep" so you can test it. It will handle zero or more copies of the same program name, first trying to terminate with SIGTERM (-15), then SIGHUP (-1) and finally SIGKILL (-9) with a warning. And if the process is still not dead, it is hung on I/O and can never be killed.</description>
      <pubDate>Mon, 19 Sep 2005 09:36:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629039#M237285</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-09-19T09:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Killing processes automatically.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629040#M237286</link>
      <description>Ops, one typo:&lt;BR /&gt; &lt;BR /&gt;echo "(kill -9 $PIDNUM required)&lt;BR /&gt; &lt;BR /&gt;is missing " at the end, should look like this:&lt;BR /&gt; &lt;BR /&gt;echo "(kill -9 $PIDNUM required)"</description>
      <pubDate>Mon, 19 Sep 2005 09:41:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629040#M237286</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-09-19T09:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Killing processes automatically.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629041#M237287</link>
      <description>Thanks a lot Bill.I will sure follow your instructions.&lt;BR /&gt;&lt;BR /&gt;Santosh Jha</description>
      <pubDate>Tue, 20 Sep 2005 03:44:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629041#M237287</guid>
      <dc:creator>santosh jha</dc:creator>
      <dc:date>2005-09-20T03:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Killing processes automatically.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629042#M237288</link>
      <description>Instead of relying on ps,&lt;BR /&gt;&lt;BR /&gt;Try&lt;BR /&gt;&lt;BR /&gt;fuser -k programname&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If Weblogic as startup script use the traditional shutdown and startup&lt;BR /&gt;/sbin/init.d/weblogic restart&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;/sbin/init.d/weblogic stop&lt;BR /&gt;/sbin/init.d/weblogic start&lt;BR /&gt;&lt;BR /&gt;Rory&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Sep 2005 12:49:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-processes-automatically/m-p/3629042#M237288</guid>
      <dc:creator>Rory R Hammond</dc:creator>
      <dc:date>2005-09-20T12:49:22Z</dc:date>
    </item>
  </channel>
</rss>

