<?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 a process by command name in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682545#M245682</link>
    <description>Whatever you do, do NOT use grep or awk or to search through the ps output!! While you may have a very unique process name for this script, grep and awk do NOT match just the process name. They look at the entire line and this can lead to drastic consequences. The simplest example is trying to kill all processes named "sh". The grep/awk pattern matching will match all occurances of unhasdaemon, bash, ksh. It will also match pathnames such as /usr/local/bin/dash45, and will match userID's such as henshaw and sherry (and kill all their processes!).&lt;BR /&gt; &lt;BR /&gt;ps has a very important but overlooked option: -C proc_name. It is only valid when the temporary variable UNIX95 is set. Compare the output of these two commands:&lt;BR /&gt; &lt;BR /&gt;ps -ef | grep sh&lt;BR /&gt;UNIX95=1 ps -f -C sh&lt;BR /&gt; &lt;BR /&gt;So always use ps (not grep or awk or other pattern matching) to find the exact name of a process. You can have multiple -C options to search for several process names.</description>
    <pubDate>Thu, 01 Dec 2005 19:36:52 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2005-12-01T19:36:52Z</dc:date>
    <item>
      <title>Killing a process by command name</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682539#M245676</link>
      <description>Is there a simple method to kill a process by it's command name that could be run as a cronjob?  There could possibly be multiple instances of the same command name.</description>
      <pubDate>Thu, 01 Dec 2005 12:38:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682539#M245676</guid>
      <dc:creator>Tom Grill</dc:creator>
      <dc:date>2005-12-01T12:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process by command name</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682540#M245677</link>
      <description>Tom,&lt;BR /&gt;&lt;BR /&gt;You can set up a script like this to be placed in cron:&lt;BR /&gt;&lt;BR /&gt;ps -ef |grep "command" |grep -v "grep" |awk '{ print $2 }' &amp;gt; /tmp/killlist&lt;BR /&gt;for i in `cat /tmp/killlist`&lt;BR /&gt;do&lt;BR /&gt;kill $i&lt;BR /&gt;sleep 1&lt;BR /&gt;kill -9 $i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Thu, 01 Dec 2005 12:55:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682540#M245677</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2005-12-01T12:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process by command name</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682541#M245678</link>
      <description>Hi Tom:&lt;BR /&gt;&lt;BR /&gt;To do this safely do this:&lt;BR /&gt;&lt;BR /&gt;# TASK=/usr/bin/sleep #...for example, only!&lt;BR /&gt;&lt;BR /&gt;# PIDS=`UNIX95= ps -C ${TASK##*/} -o pid='` &lt;BR /&gt;if [ ! -z  "${PIDS}" ]; then&lt;BR /&gt;  kill  -1  ${PIDS} &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;  sleep  3&lt;BR /&gt;  kill  -15 ${PIDS} &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;  sleep  3&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 UNIX95 variation with the '-C' switch finds *only* the prcoess with a basename that matches its argument.&lt;BR /&gt;&lt;BR /&gt;The three-level kill gives the process a chance to catch the signal and cleanup temporary files and/or shared memory segements.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Dec 2005 13:01:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682541#M245678</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-12-01T13:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process by command name</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682542#M245679</link>
      <description>Hi Tom ,&lt;BR /&gt;&lt;BR /&gt;You can do simply with this :&lt;BR /&gt;&lt;BR /&gt;# PID= $(ps -ef | grep "command" | grep -v grep | awk '{print $2}') &amp;gt; kill.list&lt;BR /&gt;&lt;BR /&gt;#&lt;BR /&gt;for i in `cat kill.list`&lt;BR /&gt;do&lt;BR /&gt;kill -SIGHUP $i&lt;BR /&gt;echo "sent SIGHUP to PID = $i ."&lt;BR /&gt;sleep 1&lt;BR /&gt;kill -9 $i&lt;BR /&gt;echo "sent SIGKILL to PID = $i ."&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You can include in a script and put that in a cron to execute as per need.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hth,&lt;BR /&gt;Raj.&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Dec 2005 13:25:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682542#M245679</guid>
      <dc:creator>Raj D.</dc:creator>
      <dc:date>2005-12-01T13:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process by command name</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682543#M245680</link>
      <description>Correction pls:&lt;BR /&gt;instead of PID= its :&lt;BR /&gt;&lt;BR /&gt;# ps -ef | grep "command" | grep -v grep | awk '{print $2}' &amp;gt; kill.list  &lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Raj.</description>
      <pubDate>Thu, 01 Dec 2005 13:28:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682543#M245680</guid>
      <dc:creator>Raj D.</dc:creator>
      <dc:date>2005-12-01T13:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process by command name</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682544#M245681</link>
      <description>Relying on grep for this is dangerous although grep -E with some careful anchoring will work. The problem is suppose you are trying to kill "myproc". Well "myproc" will match but also "notmyproc", "myproc23", etc. will also match using grep. A better approach is to extract just the process name and use it.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset TARGET=${1} # process to kill&lt;BR /&gt;shift&lt;BR /&gt;typeset -i PID=0&lt;BR /&gt;typeset PROC=''&lt;BR /&gt;&lt;BR /&gt;ps -e | awk '{print $1,$NF}' | while read PID PROC&lt;BR /&gt;  do&lt;BR /&gt;    if [[ "${PROC}" = "${TARGET}" ]]&lt;BR /&gt;      then&lt;BR /&gt;        kill -15 ${PID}&lt;BR /&gt;      fi&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt;I am assuming that the process you are not trying kill is awk; if so then additional logic will be needed.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Dec 2005 13:45:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682544#M245681</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-12-01T13:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process by command name</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682545#M245682</link>
      <description>Whatever you do, do NOT use grep or awk or to search through the ps output!! While you may have a very unique process name for this script, grep and awk do NOT match just the process name. They look at the entire line and this can lead to drastic consequences. The simplest example is trying to kill all processes named "sh". The grep/awk pattern matching will match all occurances of unhasdaemon, bash, ksh. It will also match pathnames such as /usr/local/bin/dash45, and will match userID's such as henshaw and sherry (and kill all their processes!).&lt;BR /&gt; &lt;BR /&gt;ps has a very important but overlooked option: -C proc_name. It is only valid when the temporary variable UNIX95 is set. Compare the output of these two commands:&lt;BR /&gt; &lt;BR /&gt;ps -ef | grep sh&lt;BR /&gt;UNIX95=1 ps -f -C sh&lt;BR /&gt; &lt;BR /&gt;So always use ps (not grep or awk or other pattern matching) to find the exact name of a process. You can have multiple -C options to search for several process names.</description>
      <pubDate>Thu, 01 Dec 2005 19:36:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682545#M245682</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-12-01T19:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process by command name</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682546#M245683</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;for PidNbr in $(ps -ef|awk '$1=="user"&amp;amp;&amp;amp;$8="command" {print $2}')&lt;BR /&gt;do&lt;BR /&gt;  kill $PidNbr&lt;BR /&gt;done&lt;BR /&gt;for PidNbr in $(ps -ef|awk '$1=="user"&amp;amp;&amp;amp;$8="command" {print $2}')&lt;BR /&gt;do&lt;BR /&gt;  kill -9 $PidNbr&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;where user is the UNIX user if the command, and command is the comamnd you want to kill.&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Art</description>
      <pubDate>Fri, 02 Dec 2005 04:23:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/killing-a-process-by-command-name/m-p/3682546#M245683</guid>
      <dc:creator>Arturo Galbiati</dc:creator>
      <dc:date>2005-12-02T04:23:07Z</dc:date>
    </item>
  </channel>
</rss>

