<?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: getpid in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725887#M788809</link>
    <description>Hi Tom, &lt;BR /&gt;&lt;BR /&gt;You can take a look at, /sbin/init.d/template&lt;BR /&gt;to write your own startup script. &lt;BR /&gt;&lt;BR /&gt;-Arun</description>
    <pubDate>Tue, 07 Feb 2006 06:02:45 GMT</pubDate>
    <dc:creator>Arunvijai_4</dc:creator>
    <dc:date>2006-02-07T06:02:45Z</dc:date>
    <item>
      <title>getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725886#M788808</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I've created a script that monitors a process that runs in on our sever.  I have also created a script in /etc/rc.config.d/ and /sbin/init.d to start this script at boot time. however i want to create a file that contains the PID of this script.  From within the script i want to divert the process id to a file so my init script knows which process to kill. I  know getpid does this but i am not sure how to use it.... can someone help?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;also is this alright? do i need to background it??&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;PATH=/sbin:/usr/sbin:/usr/bin&lt;BR /&gt;export PATH&lt;BR /&gt;&lt;BR /&gt;if [ -r /etc/rc.config.d/ecommalert ]&lt;BR /&gt;then &lt;BR /&gt;    . /etc/rc.config.d/ecommalert&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;case "$1" in&lt;BR /&gt;&lt;BR /&gt;    "start") if [ "$ECOMMSTART" -ne 0 ]&lt;BR /&gt;             then&lt;BR /&gt;               /ops/scripts/ecommalert&amp;amp; &lt;BR /&gt;               exit 0&lt;BR /&gt;             fi&lt;BR /&gt;             exit 2 ;;&lt;BR /&gt;&lt;BR /&gt;    "stop") if [ "$ECOMMSTART" -ne 0 ]&lt;BR /&gt;            then&lt;BR /&gt;               /ops/scripts/ecommstop&lt;BR /&gt;               exit 0&lt;BR /&gt;            fi&lt;BR /&gt;            exit 2 ;;&lt;BR /&gt;    *)&lt;BR /&gt;        echo "usage: $0 {start|stop}"&lt;BR /&gt;        exit 1&lt;BR /&gt;        ;;&lt;BR /&gt;esac&lt;BR /&gt;&lt;BR /&gt;exit 0;</description>
      <pubDate>Tue, 07 Feb 2006 05:51:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725886#M788808</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2006-02-07T05:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725887#M788809</link>
      <description>Hi Tom, &lt;BR /&gt;&lt;BR /&gt;You can take a look at, /sbin/init.d/template&lt;BR /&gt;to write your own startup script. &lt;BR /&gt;&lt;BR /&gt;-Arun</description>
      <pubDate>Tue, 07 Feb 2006 06:02:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725887#M788809</guid>
      <dc:creator>Arunvijai_4</dc:creator>
      <dc:date>2006-02-07T06:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725888#M788810</link>
      <description>thanks, but i'm more concerned with get the PID of the script. thanks:-)</description>
      <pubDate>Tue, 07 Feb 2006 06:04:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725888#M788810</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2006-02-07T06:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725889#M788811</link>
      <description>Hello, &lt;BR /&gt;&lt;BR /&gt;For PID, you can take a look at Secure shell's startup script /sbin/init.d/secsh. It should help you. &lt;BR /&gt;&lt;BR /&gt;-Arun</description>
      <pubDate>Tue, 07 Feb 2006 06:07:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725889#M788811</guid>
      <dc:creator>Arunvijai_4</dc:creator>
      <dc:date>2006-02-07T06:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725890#M788812</link>
      <description>not really. &lt;BR /&gt;&lt;BR /&gt;that the sshd writes the PID to a file. this script just cats it and assigns that to a variable.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Feb 2006 06:11:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725890#M788812</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2006-02-07T06:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725891#M788813</link>
      <description>sorry, maybe i was not clear.&lt;BR /&gt;&lt;BR /&gt;from within the script (not the init.d or rc.config.d) that actually monitors the process. Say its called 'ecommalert'.  I want 'ecommalert' to get its own PID and send that to a file.&lt;BR /&gt;&lt;BR /&gt;ecommalert will be started at run level 3.&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Feb 2006 06:16:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725891#M788813</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2006-02-07T06:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725892#M788814</link>
      <description>Hello, &lt;BR /&gt;&lt;BR /&gt;You can probably use something like this, &lt;BR /&gt;&lt;BR /&gt;echo "ecomalert PID is $$" &amp;gt;ecom.pid&lt;BR /&gt;&lt;BR /&gt;-Arun &lt;BR /&gt;P.S Remember to assign points. &lt;BR /&gt;</description>
      <pubDate>Tue, 07 Feb 2006 06:21:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725892#M788814</guid>
      <dc:creator>Arunvijai_4</dc:creator>
      <dc:date>2006-02-07T06:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725893#M788815</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You can't use getpid() from a shell script,&lt;BR /&gt;it should be the process (written in a language like C) that call that function and writes its PID in a file.&lt;BR /&gt;&lt;BR /&gt;From shell you can only do somenthing like:&lt;BR /&gt;&lt;BR /&gt;# ps -efx | grep &lt;PROCNAME&gt;&lt;BR /&gt;&lt;BR /&gt;Pablo&lt;/PROCNAME&gt;</description>
      <pubDate>Tue, 07 Feb 2006 06:22:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725893#M788815</guid>
      <dc:creator>paolo barila</dc:creator>
      <dc:date>2006-02-07T06:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725894#M788816</link>
      <description>Shalom,&lt;BR /&gt;&lt;BR /&gt;You may find some Linux code useful in this regard.&lt;BR /&gt;&lt;BR /&gt; /usr/local/cluster/cluster.mon &amp;amp;&lt;BR /&gt;        RETVAL=$?&lt;BR /&gt;        echo&lt;BR /&gt;        [ $RETVAL = 0 ] &amp;amp;&amp;amp; touch /var/lock/subsys/cluster.mon&lt;BR /&gt;        return $RETVAL&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;thats from a clsuter monitor script. It creates a lock file by PID.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Tue, 07 Feb 2006 06:30:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725894#M788816</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2006-02-07T06:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725895#M788817</link>
      <description>Hi Tom:&lt;BR /&gt;&lt;BR /&gt;The following shell variables are directly available to you:&lt;BR /&gt;&lt;BR /&gt;?? -&amp;gt; the process number of the current shell&lt;BR /&gt;&lt;BR /&gt;?! -&amp;gt; the process number of the last background command&lt;BR /&gt;&lt;BR /&gt;Does this help?&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 07 Feb 2006 07:20:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725895#M788817</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-02-07T07:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725896#M788818</link>
      <description>A simple C program that use getpid()&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;printf("Salve mondo!\n");&lt;BR /&gt;printf("PID= %d\n", getpid());&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Tue, 07 Feb 2006 07:27:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725896#M788818</guid>
      <dc:creator>paolo barila</dc:creator>
      <dc:date>2006-02-07T07:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725897#M788819</link>
      <description>Not sure if this will help, but by using the basename of the script you can get the PID and pass it to a file, like in this example, used to get the PID of the scopeux process:&lt;BR /&gt;&lt;BR /&gt;UNIX95= ps -C scopeux -o pid= &amp;gt; scopeux.pid</description>
      <pubDate>Tue, 07 Feb 2006 09:16:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725897#M788819</guid>
      <dc:creator>Andy Torres</dc:creator>
      <dc:date>2006-02-07T09:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725898#M788820</link>
      <description>Hi Tom.&lt;BR /&gt;Do you want to stop the ecommalert or the process this script is monitoring (or both)?&lt;BR /&gt;&lt;BR /&gt;If ecommalert is a script, you could simply add a line which echo the PID to a file during startup.&lt;BR /&gt;&lt;BR /&gt;example:&lt;BR /&gt;echo "$$" &amp;gt;/ops/scripts/ecommalert.pid&lt;BR /&gt;&lt;BR /&gt;As others have mentioned it is not that simple if the ecommalert is a binary.&lt;BR /&gt;&lt;BR /&gt;Another approach could be to use a killproc function.&lt;BR /&gt;You could have a look in /sbin/init.d/nfs.client to see how it is used, and how to define the function.&lt;BR /&gt;&lt;BR /&gt;This use a unique string input on the process you want to kill, rather than the PID itself.&lt;BR /&gt;&lt;BR /&gt;Example&lt;BR /&gt;You would be writing:&lt;BR /&gt;  killproc ecommalert&lt;BR /&gt;Instead of writing:&lt;BR /&gt;  kill `cat /ops/scripts/ecommalert.pid`&lt;BR /&gt;&lt;BR /&gt;The killproc function will use ps to find and grep the correct process, then kill it.&lt;BR /&gt;&lt;BR /&gt;======= some hint/tips =======&lt;BR /&gt;If you use a PID-file you can check if the process is alive with this command:&lt;BR /&gt;#sh-posix syntax&lt;BR /&gt;kill -0 `cat /ops/scripts/ecommalert.pid` || {&lt;BR /&gt;  print "Warning: No such process"&lt;BR /&gt;  rm -f /ops/scripts/ecommalert.pid&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;In the /sbin/init.d/nfs.client you should notice these three functions.&lt;BR /&gt;killproc : "nice kill"&lt;BR /&gt;killbiod : identical, but "sure kill" (-9)&lt;BR /&gt;findproc : returning the PID for a named process&lt;BR /&gt;&lt;BR /&gt;To test this I suggest you copy the functions into a new script which you can do some testing with.&lt;BR /&gt;Then change the kill $pid to echo "kill $pid"&lt;BR /&gt;Then you can safely try it out and see that the correct PID's are used.&lt;BR /&gt;&lt;BR /&gt;Last hint:&lt;BR /&gt;If you have many functions which is useful for many purposes you can define these in separate files.&lt;BR /&gt;example: &lt;BR /&gt;/ops/scripts/Functions/killproc&lt;BR /&gt;/ops/scripts/Functions/findproc&lt;BR /&gt;containing the function(s) from nfs.client&lt;BR /&gt;When you want to use functions in /ops/scripts/Functions you simply set the environment variable FPATH&lt;BR /&gt;(export FPATH=/ops/scripts/Functions)&lt;BR /&gt;- and then they're ready for use.&lt;BR /&gt;can be used both in scripts as well as from command-line.&lt;BR /&gt;&lt;BR /&gt;To see functions defined: typeset -f&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Tor-Arne</description>
      <pubDate>Wed, 08 Feb 2006 11:53:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725898#M788820</guid>
      <dc:creator>Tor-Arne Nostdal</dc:creator>
      <dc:date>2006-02-08T11:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725899#M788821</link>
      <description>Hey thanks! :-)&lt;BR /&gt;&lt;BR /&gt;this is very useful to me.&lt;BR /&gt;&lt;BR /&gt;I am just using a shell script now, before i learn C. but i am very interesting in process control.&lt;BR /&gt;&lt;BR /&gt;I'll go away and do some testing :-)&lt;BR /&gt;&lt;BR /&gt;Thanks for your time.</description>
      <pubDate>Wed, 08 Feb 2006 12:00:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725899#M788821</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2006-02-08T12:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725900#M788822</link>
      <description>UNIX95 is a good way to go:&lt;BR /&gt;&lt;BR /&gt;MYPID="$(UNIX95= ps -C $MYPROC -o pid=)"&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff</description>
      <pubDate>Wed, 08 Feb 2006 12:14:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725900#M788822</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2006-02-08T12:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725901#M788823</link>
      <description>yes i'm using that, it's cool</description>
      <pubDate>Wed, 08 Feb 2006 12:15:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725901#M788823</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2006-02-08T12:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725902#M788824</link>
      <description>When something is useful we appreaciate assigned points ;-))</description>
      <pubDate>Wed, 08 Feb 2006 12:16:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725902#M788824</guid>
      <dc:creator>Tor-Arne Nostdal</dc:creator>
      <dc:date>2006-02-08T12:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725903#M788825</link>
      <description>as you will see i have assigned 100% of points so far. impatience eh! ok ok......</description>
      <pubDate>Wed, 08 Feb 2006 12:17:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725903#M788825</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2006-02-08T12:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725904#M788826</link>
      <description>he, he...&lt;BR /&gt;The points are encouraging activity, though most sysadmins is willing to help out and share knowledge even if it doesn't "pay off". It's almost as built into the spinal cord :-))</description>
      <pubDate>Wed, 08 Feb 2006 12:36:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725904#M788826</guid>
      <dc:creator>Tor-Arne Nostdal</dc:creator>
      <dc:date>2006-02-08T12:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: getpid</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725905#M788827</link>
      <description>one question i have - if i run a script from an init script, do i need to background it (&amp;amp;), or can i just run it?&lt;BR /&gt;&lt;BR /&gt;bearing in mind the script runs for ever...</description>
      <pubDate>Thu, 09 Feb 2006 04:42:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/getpid/m-p/3725905#M788827</guid>
      <dc:creator>Tom Satinet</dc:creator>
      <dc:date>2006-02-09T04:42:23Z</dc:date>
    </item>
  </channel>
</rss>

