<?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: kill a process in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561310#M29388</link>
    <description>Hi&lt;BR /&gt;&lt;BR /&gt;   Sorry i missed &lt;BR /&gt;grep -v java&lt;BR /&gt;&lt;BR /&gt;it should be&lt;BR /&gt;PID=`ps -ef | grep java | grep -v java|awk '{ print $2}'`</description>
    <pubDate>Fri, 03 Aug 2001 12:19:45 GMT</pubDate>
    <dc:creator>Praveen Bezawada</dc:creator>
    <dc:date>2001-08-03T12:19:45Z</dc:date>
    <item>
      <title>kill a process</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561306#M29384</link>
      <description>Hello I am not a scripting expert and would like to know the best way to grep and kill a process within a script.  Any help will be appreciated.  Thanks</description>
      <pubDate>Fri, 03 Aug 2001 12:08:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561306#M29384</guid>
      <dc:creator>Gerald Taylor</dc:creator>
      <dc:date>2001-08-03T12:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: kill a process</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561307#M29385</link>
      <description>Hi&lt;BR /&gt;   &lt;BR /&gt;   Suppose you want to kill a java process you can do&lt;BR /&gt;&lt;BR /&gt;PID=`ps -ef | grep java | awk '{ print $2 }'`&lt;BR /&gt;kill -9 $PID&lt;BR /&gt;&lt;BR /&gt;   This kill the java process.</description>
      <pubDate>Fri, 03 Aug 2001 12:13:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561307#M29385</guid>
      <dc:creator>Praveen Bezawada</dc:creator>
      <dc:date>2001-08-03T12:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: kill a process</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561308#M29386</link>
      <description>Hi Gerald:&lt;BR /&gt;&lt;BR /&gt;Here's one simple way to kill by process name:&lt;BR /&gt;&lt;BR /&gt;TASK=/usr/local/bin/my.sh #...for example!&lt;BR /&gt;&lt;BR /&gt;PIDS=`ps -ef|grep "$TASK"|grep -v "grep $TASK"|awk '{print $2}'`&lt;BR /&gt;#&lt;BR /&gt;if [ ! -z "$PIDS" ]&lt;BR /&gt;then&lt;BR /&gt;  kill     $PIDS &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;  sleep 5&lt;BR /&gt;  kill -9  $PIDS &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;The idea is to kill, first gracefully (!) and then brutally the TASK(s) by name.  The 'grep -v' eliminates finding the 'grep' process itself.  The 'pid' of the TASK is isolated and used in the 'kill'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 03 Aug 2001 12:17:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561308#M29386</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-08-03T12:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: kill a process</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561309#M29387</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I would modify the last response as follow :&lt;BR /&gt;&lt;BR /&gt;PID=`ps -ef | grep -v grep ? grep java | awk '{ print $2 }'` &lt;BR /&gt;&lt;BR /&gt;for currPid in PID&lt;BR /&gt;do&lt;BR /&gt;kill -9 $PID &lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;java in the command "grep java" would be replaced by the process name that you are looking for.&lt;BR /&gt;&lt;BR /&gt;This version run for multiple process killing under the same name.&lt;BR /&gt;&lt;BR /&gt;Magdi&lt;BR /&gt;</description>
      <pubDate>Fri, 03 Aug 2001 12:19:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561309#M29387</guid>
      <dc:creator>Magdi KAMAL</dc:creator>
      <dc:date>2001-08-03T12:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: kill a process</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561310#M29388</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;   Sorry i missed &lt;BR /&gt;grep -v java&lt;BR /&gt;&lt;BR /&gt;it should be&lt;BR /&gt;PID=`ps -ef | grep java | grep -v java|awk '{ print $2}'`</description>
      <pubDate>Fri, 03 Aug 2001 12:19:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561310#M29388</guid>
      <dc:creator>Praveen Bezawada</dc:creator>
      <dc:date>2001-08-03T12:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: kill a process</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561311#M29389</link>
      <description>Oooops,&lt;BR /&gt;&lt;BR /&gt;Sorry, kill command operates on $currPid and not $PID.&lt;BR /&gt;&lt;BR /&gt;I would modify the last response as follow : &lt;BR /&gt;&lt;BR /&gt;PID=`ps -ef | grep -v grep ? grep java | awk '{ print $2 }'` &lt;BR /&gt;&lt;BR /&gt;for currPid in PID &lt;BR /&gt;do &lt;BR /&gt;kill -9 $currPid &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;java in the command "grep java" would be replaced by the process name that you are looking for. &lt;BR /&gt;&lt;BR /&gt;This version run for multiple process killing under the same name. &lt;BR /&gt;&lt;BR /&gt;Magdi &lt;BR /&gt;</description>
      <pubDate>Fri, 03 Aug 2001 12:21:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561311#M29389</guid>
      <dc:creator>Magdi KAMAL</dc:creator>
      <dc:date>2001-08-03T12:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: kill a process</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561312#M29390</link>
      <description>Hi :&lt;BR /&gt;&lt;BR /&gt;Doing something like:&lt;BR /&gt;&lt;BR /&gt;# PIDS=`ps -ef|grep java|grep -v java|awk '{print $2}'&lt;BR /&gt;&lt;BR /&gt;...collects zero or more pids of "java" processes (at least those with the string "java" somewhere in the line returned).&lt;BR /&gt;&lt;BR /&gt;'kill' allows a list of pids to be specified, so:&lt;BR /&gt;&lt;BR /&gt;# kill $PIDS&lt;BR /&gt;&lt;BR /&gt;...would kill the list in "one shot".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 03 Aug 2001 12:47:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561312#M29390</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-08-03T12:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: kill a process</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561313#M29391</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;A for loop will be sufficient.&lt;BR /&gt;&lt;BR /&gt;for Pid in `ps -ef | grep -v grep ? grep java | awk '{ print $2 }'` &lt;BR /&gt;do &lt;BR /&gt;kill -9 $Pid &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Joe.&lt;BR /&gt;</description>
      <pubDate>Fri, 03 Aug 2001 12:53:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561313#M29391</guid>
      <dc:creator>Joseph Chakkery</dc:creator>
      <dc:date>2001-08-03T12:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: kill a process</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561314#M29392</link>
      <description>DON'T EVER GET IN THE HABIT OF USING kill -9!!&lt;BR /&gt;&lt;BR /&gt;kill -9 will corrupt datafiles and leave a lot of work for application support to clean up. Kill -9 bypasses ALL of the program's code for graceful termination including flushing internal buffers, closing files correctly and writing appropriate messages to logfiles. Not all programs have this code but certainly databases and large scale data analysis do have this capability. kill -9 is used ONLY as a last resort. Use kill -15 (which is the default for kill)&lt;BR /&gt;&lt;BR /&gt;I would also be VERY careful with using grep for finding process names.  Using: "ps -e | grep java" will find all the lines in the ps listing with java INCLUDING user logins such as javabob and javaier, and process names such as java1 and w6javaw4....you certainly don't want to kill all those processes.  grep doesn't know anything except string matches.&lt;BR /&gt;&lt;BR /&gt;Instead, change your task to either accept the process ID (PID) number so there is no question as to which process you want killed, or to kill a process by name, you must decide what to do if there are multiple copies of the same process.&lt;BR /&gt;&lt;BR /&gt;Start by identifying the process by name (really, basename of the executable file used to start the process:&lt;BR /&gt;&lt;BR /&gt;UNIX95= ps -C java&lt;BR /&gt;&lt;BR /&gt;This eliminates grep'ing for grep and finding things that are partial matches.  To test this, try something you know is running like:&lt;BR /&gt;&lt;BR /&gt;UNIX95= ps -C sh&lt;BR /&gt;&lt;BR /&gt;Notice that it finds all sh commands but not ksh and even finds the login shells (ie, -sh). NOTE: Type the "UNIX95= ps" exactly as shown--it is a special flag to turn on unique XPG4 behavior. Don't export UNIX95 as it will change the behavior a several commands and library calls.&lt;BR /&gt;&lt;BR /&gt;Now that you have a way to locate just a specific executable by name, you'll need to decide if killing multiple copies is the correct action.  If not, show the list and manually pick the PID that is needed.  Here is a simple script to kill a process by name:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;# Kill a single process by name&lt;BR /&gt;# USAGE:&lt;BR /&gt;&lt;BR /&gt;if [ $# -ne 1 ]&lt;BR /&gt;then&lt;BR /&gt;   echo "Usage: $0 process-name"&lt;BR /&gt;   exit 1&lt;BR /&gt;else&lt;BR /&gt;   MYNAME=$1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;# Search for process by basename&lt;BR /&gt;&lt;BR /&gt;MYLIST=$(UNIX95= /usr/bin/ps -C $MYNAME -o pid | grep -v PID )&lt;BR /&gt;&lt;BR /&gt;# None?&lt;BR /&gt;&lt;BR /&gt;if [ -z "$MYLIST" ]&lt;BR /&gt;then&lt;BR /&gt;   echo "No process running called $MYNAME"&lt;BR /&gt;&lt;BR /&gt;# More than 1?&lt;BR /&gt;&lt;BR /&gt;elif [ $(echo $MYLIST | /usr/bin/wc -w) -gt 1 ]&lt;BR /&gt;then&lt;BR /&gt;   echo "More than 1 process called $MYNAME:"&lt;BR /&gt;   UNIX95= /usr/bin/ps -fC $MYNAME&lt;BR /&gt;&lt;BR /&gt;# Just 1 so kill -15, wait, then check again&lt;BR /&gt;&lt;BR /&gt;else&lt;BR /&gt;   MYPID=$(echo $MYLIST | awk '{print $1}')&lt;BR /&gt;   kill $MYPID&lt;BR /&gt;   sleep 2&lt;BR /&gt;&lt;BR /&gt;# Did it work? If ps succeeds, kill did not work&lt;BR /&gt;&lt;BR /&gt;   if /usr/bin/ps -p $MYPID &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;   then&lt;BR /&gt;     echo "$MYNAME (PID=$MYPID) ignoring normal kill"&lt;BR /&gt;     /usr/bin/ps -fp $MYPID&lt;BR /&gt;fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;---&lt;BR /&gt;&lt;BR /&gt;This script tests that you supplied 1 and only 1 process name to kill, then verifies that there is 1 and only 1 process with that name running, and finally, after killing it with -15, verifies that it has disappeared.  If not, it shows the process information for manual intervention.</description>
      <pubDate>Fri, 03 Aug 2001 14:18:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561314#M29392</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2001-08-03T14:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: kill a process</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561315#M29393</link>
      <description>Hi Gerald:&lt;BR /&gt;&lt;BR /&gt;A further comment/contribution:&lt;BR /&gt;&lt;BR /&gt;As Bill explicitly pointed out, and as I implicitly hinted, the 'grep' syntax used in the examples provided would return matches for the expression *anywhere* in the line -- potentially dangerous.&lt;BR /&gt;&lt;BR /&gt;A more rigorous snipet of code to kill a process by name can be seen in the killproc() function of /sbin/init.d/template.&lt;BR /&gt;&lt;BR /&gt;This code isolates the expression to match to the last field returned by 'ps' and ignores its own processes, analogous to using the 'grep -v' in the other examples provided.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 03 Aug 2001 14:44:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561315#M29393</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-08-03T14:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: kill a process</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561316#M29394</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I'll add one more thing to the kill -9 issue.&lt;BR /&gt;Before you resort to -9 try using kill -11; it's almost as sure a kill and it does clean up so that file descriptors are closed and shared memory is detached. My ususal sequence if to do a kill -15, kill -1, kill -2, kill -11, and finally any only if I really,really need to kill this process a kill -9.&lt;BR /&gt;&lt;BR /&gt;I typically do something like this in a shell function&lt;BR /&gt;kill_pids()&lt;BR /&gt;{&lt;BR /&gt;  DELAY=5&lt;BR /&gt;  STAT=0&lt;BR /&gt;  SIGS="15 1 2 11"&lt;BR /&gt;  while [ $# -ge 1 ]&lt;BR /&gt;     do&lt;BR /&gt;       THIS_PID=$1&lt;BR /&gt;       shift&lt;BR /&gt;       for SIG in ${SIGS}&lt;BR /&gt;         do&lt;BR /&gt;           kill -s 0 ${THIS_PID} &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;           STAT=$?&lt;BR /&gt;           if [ ${STAT} -ne 0 ]&lt;BR /&gt;             then&lt;BR /&gt;               break&lt;BR /&gt;             fi&lt;BR /&gt;           kill -s ${SIG} ${THIS_PID}&lt;BR /&gt;           STAT=$?&lt;BR /&gt;           sleep ${DELAY}&lt;BR /&gt;         done&lt;BR /&gt;     done&lt;BR /&gt;   return ${STAT}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Note that you can send a kill -0 pid (or kill -s 0 pid) and check the status to test if the process is valid. If you like you can add 9 to the ${SIGS} and thus also have the 'killer' kill. In practice, kill -11 almost always get 'em.&lt;BR /&gt;&lt;BR /&gt;Regards, Clay</description>
      <pubDate>Fri, 03 Aug 2001 15:12:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/kill-a-process/m-p/2561316#M29394</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-08-03T15:12:03Z</dc:date>
    </item>
  </channel>
</rss>

