<?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 within a script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960875#M101191</link>
    <description>&lt;BR /&gt;For the simple opne-liners as per above, I prefer a trivial regexpr versus the 'grep -v grep'&lt;BR /&gt;&lt;BR /&gt;Something like: ps -ef | grep [P]ROCESSNAME&lt;BR /&gt;&lt;BR /&gt;Here the grepped string no longer matches itself as [P] really is just P.&lt;BR /&gt;&lt;BR /&gt;And if one goes into awk anyway, why not have it do it all? It gives the oppurtunity for additional tests, log messages, whatever...&lt;BR /&gt;&lt;BR /&gt;To pick up a variabled (processname?) into awk, check the manpages. Notably: -v and x=y and the ENVIRON[] built-in array.&lt;BR /&gt;&lt;BR /&gt;ps -ef | awk '/PROCESSNAME/ { system ("kill -9 " $2)}'&lt;BR /&gt;&lt;BR /&gt;fwiw,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Sat, 18 Feb 2006 08:04:49 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2006-02-18T08:04:49Z</dc:date>
    <item>
      <title>Killing a process within a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960873#M101189</link>
      <description>Hi everyone,&lt;BR /&gt;&lt;BR /&gt;What would be the easiest way to kill a process within a script?  I'm wanting to perform a ps on something and then kill that process through automation.  Thanks for your help.</description>
      <pubDate>Fri, 17 Feb 2006 21:32:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960873#M101189</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2006-02-17T21:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process within a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960874#M101190</link>
      <description>Hi,&lt;BR /&gt;I would do something like&lt;BR /&gt;&lt;BR /&gt;# kill -9 `ps -ef | grep PROCESSNAME | grep -v grep | awk '{print $2}'`&lt;BR /&gt;&lt;BR /&gt;Pablo&lt;BR /&gt;</description>
      <pubDate>Sat, 18 Feb 2006 07:49:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960874#M101190</guid>
      <dc:creator>paolo barila</dc:creator>
      <dc:date>2006-02-18T07:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process within a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960875#M101191</link>
      <description>&lt;BR /&gt;For the simple opne-liners as per above, I prefer a trivial regexpr versus the 'grep -v grep'&lt;BR /&gt;&lt;BR /&gt;Something like: ps -ef | grep [P]ROCESSNAME&lt;BR /&gt;&lt;BR /&gt;Here the grepped string no longer matches itself as [P] really is just P.&lt;BR /&gt;&lt;BR /&gt;And if one goes into awk anyway, why not have it do it all? It gives the oppurtunity for additional tests, log messages, whatever...&lt;BR /&gt;&lt;BR /&gt;To pick up a variabled (processname?) into awk, check the manpages. Notably: -v and x=y and the ENVIRON[] built-in array.&lt;BR /&gt;&lt;BR /&gt;ps -ef | awk '/PROCESSNAME/ { system ("kill -9 " $2)}'&lt;BR /&gt;&lt;BR /&gt;fwiw,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 18 Feb 2006 08:04:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960875#M101191</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-02-18T08:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process within a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960876#M101192</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;First, make usre that you isolate the process that you *really* want.  Use the XPG4 (UNIX95) options of 'ps' achieves this.  &lt;BR /&gt;&lt;BR /&gt;Never kill with 'kill -9' except as a last resort.  A 'kill -9' cannot be ignored or trapped and it doesn't give a process any chance to clean up shared memory segments or remove temporary files.&lt;BR /&gt;&lt;BR /&gt;Instead, use a multi-level kill, starting with a hangup; then a simple 'kill -15'; and as a last resort a 'kill -9'.&lt;BR /&gt;&lt;BR /&gt;The following code accomplishs the above.  If any level of killing succeeds, the script exits.&lt;BR /&gt;&lt;BR /&gt;# cat .killer&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;myproc=`basename ${1}`&lt;BR /&gt;mypid=`UNIX95= ps -C ${myproc} -o pid=`&lt;BR /&gt;if [ ! -z "${mypid}" ]; then&lt;BR /&gt;    kill -1  ${mypid} 2&amp;gt;/dev/null || exit 0&lt;BR /&gt;    sleep 3&lt;BR /&gt;    kill -15 ${mypid} 2&amp;gt;/dev/null || exit 0&lt;BR /&gt;    sleep 3&lt;BR /&gt;    kill -9  ${mypid} 2&amp;gt;/dev/null &lt;BR /&gt;fi&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;You can see how this works by doing:&lt;BR /&gt;&lt;BR /&gt;# sleep 120 &amp;amp;&lt;BR /&gt;# ./killer sleep&lt;BR /&gt;&lt;BR /&gt;(or)&lt;BR /&gt;&lt;BR /&gt;# nohup /usr/bin/sleep 120 &amp;amp;&lt;BR /&gt;# ./killer sleep&lt;BR /&gt;&lt;BR /&gt;If you wish to integrate this into a subroutine in an existing script, change the 'exit' to a 'return' within the subroutine.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sat, 18 Feb 2006 08:07:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960876#M101192</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-02-18T08:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process within a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960877#M101193</link>
      <description>..and if I have more instances of a process with different parameters (let's say java) and I want kill one and only one I would use:&lt;BR /&gt;&lt;BR /&gt;# ps -efx | grep/awk...  #(&amp;gt;= hp-ux 11.11)&lt;BR /&gt;</description>
      <pubDate>Sat, 18 Feb 2006 08:42:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960877#M101193</guid>
      <dc:creator>paolo barila</dc:creator>
      <dc:date>2006-02-18T08:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process within a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960878#M101194</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;If there is any chance that you have multiple processes by the same name, the version below accomodates that.  The first version could potentially fail to kill all of the processes under certain circumstances.  The same comments apply as before, otherwise.&lt;BR /&gt;&lt;BR /&gt;# cat .killer&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;myproc=`basename ${1}`&lt;BR /&gt;[ -z "${1}" ] &amp;amp;&amp;amp; { echo "no process specified!"; exit 1; }&lt;BR /&gt;mypid=`UNIX95= ps -C ${myproc} -o pid=`&lt;BR /&gt;if [  ! -z  "${mypid}" ]; then&lt;BR /&gt;    kill -1  ${mypid} 2&amp;gt;/dev/null&lt;BR /&gt;    sleep 3&lt;BR /&gt;    kill -15 ${mypid} 2&amp;gt;/dev/null&lt;BR /&gt;    sleep 3&lt;BR /&gt;    kill -9  ${mypid} 2&amp;gt;/dev/null&lt;BR /&gt;fi&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;ENOCOFFEE ;-)</description>
      <pubDate>Sat, 18 Feb 2006 09:32:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960878#M101194</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-02-18T09:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process within a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960879#M101195</link>
      <description>OK Italian coffee for you all :-)&lt;BR /&gt;I do appreciate James' script,&lt;BR /&gt;I'm sorry for my sudden "kill -9", I was really rude. &lt;BR /&gt;&lt;BR /&gt;I still have a point:&lt;BR /&gt;Let's suppose you have 2 processes:&lt;BR /&gt;&lt;BR /&gt;# sleep 1000 &amp;amp;&lt;BR /&gt;# sleep 1001 &amp;amp;&lt;BR /&gt;&lt;BR /&gt;and you wanna stop *only* "sleep 1000"&lt;BR /&gt;&lt;BR /&gt;(java processes happen to have long parameters and I find useful the "ps -x" trick)&lt;BR /&gt;</description>
      <pubDate>Sat, 18 Feb 2006 10:34:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960879#M101195</guid>
      <dc:creator>paolo barila</dc:creator>
      <dc:date>2006-02-18T10:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process within a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960880#M101196</link>
      <description>Ciao Paolo,&lt;BR /&gt;in this case use:&lt;BR /&gt;kill $(ps -fxu &lt;USER&gt;|awk '/[s]leep 100/ {print $2}')&lt;BR /&gt;&lt;BR /&gt;trick is -x option to be able to see by PS the while command string so you will be abel to check command and parameter as well.&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Art&lt;/USER&gt;</description>
      <pubDate>Mon, 20 Feb 2006 04:13:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960880#M101196</guid>
      <dc:creator>Arturo Galbiati</dc:creator>
      <dc:date>2006-02-20T04:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process within a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960881#M101197</link>
      <description>ps -ef |grep -v -f /usr/local/bin/patt.1 |grep $1 &amp;gt; temp.1&lt;BR /&gt;sudo -u root kill -9 `awk '{print $2}' temp.1`&lt;BR /&gt;rm temp.1&lt;BR /&gt;</description>
      <pubDate>Mon, 20 Feb 2006 08:57:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960881#M101197</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2006-02-20T08:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process within a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960882#M101198</link>
      <description>Thank you all for the GREAT help!!!  I'm slowing getting better at this stuff.  At least I'm getting where I know what questions to ask now LOL.</description>
      <pubDate>Tue, 21 Feb 2006 17:39:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960882#M101198</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2006-02-21T17:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Killing a process within a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960883#M101199</link>
      <description>Closed.  Please see "Killing a process witha script PART 2"</description>
      <pubDate>Wed, 22 Feb 2006 20:36:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/killing-a-process-within-a-script/m-p/4960883#M101199</guid>
      <dc:creator>TheJuiceman</dc:creator>
      <dc:date>2006-02-22T20:36:48Z</dc:date>
    </item>
  </channel>
</rss>

