<?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: Need to monitor the existance of a process in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015781#M96721</link>
    <description>This is a common problem but in a production environment, I would not allow no-status programs to run like that. The whole concept of semaphores, or status files eliminates the large uncertainty in monitoring programs like this. The usual solution is to wait longer than the normal completion time (completely undependable). The next is to watch the programs go away as in your example. But what if the program(s) crash, or are killed or do not run correctly?&lt;BR /&gt; &lt;BR /&gt;I would strongly recommend that the other process(es) be rewritten to report an exit status, perhaps through a simple text file. And the monitoring script needs to perform a sanity check in case no completion file is created after several hours.&lt;BR /&gt; &lt;BR /&gt;If you write code with the idea that everything is going to fail, you won't be disappointed.</description>
    <pubDate>Mon, 27 Nov 2006 23:08:07 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2006-11-27T23:08:07Z</dc:date>
    <item>
      <title>Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015775#M96715</link>
      <description>All,&lt;BR /&gt;&lt;BR /&gt;I'm an idiot asking this, i know, but i need to monitor a process of it's existance.&lt;BR /&gt;A monitor script must run in a loop until the monitored process has finished. then it has to exit.&lt;BR /&gt;&lt;BR /&gt;while ....&lt;BR /&gt;&lt;BR /&gt;ps -ef | grep PROCESS&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;... &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Please fill in the blanks.&lt;BR /&gt;I have a bit of a programmers block at the moment.&lt;BR /&gt;&lt;BR /&gt;Kl@@s&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Nov 2006 10:37:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015775#M96715</guid>
      <dc:creator>Klaas D. Eenkhoorn</dc:creator>
      <dc:date>2006-11-27T10:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015776#M96716</link>
      <description>One approach...&lt;BR /&gt;&lt;BR /&gt;while [ $(ps -ef | grep PROCESS | grep -v grep) != "" ]&lt;BR /&gt;do&lt;BR /&gt;  sleep 5&lt;BR /&gt;done</description>
      <pubDate>Mon, 27 Nov 2006 10:47:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015776#M96716</guid>
      <dc:creator>Jeff_Traigle</dc:creator>
      <dc:date>2006-11-27T10:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015777#M96717</link>
      <description>Klaas,&lt;BR /&gt;many solutions possible.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;a=1&lt;BR /&gt;process="fred"&lt;BR /&gt;while [ $a -eq 1 ]&lt;BR /&gt;do&lt;BR /&gt;a=`ps -ef | grep $process | grep -v grep | wc -l`&lt;BR /&gt;done</description>
      <pubDate>Mon, 27 Nov 2006 10:50:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015777#M96717</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-11-27T10:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015778#M96718</link>
      <description>&lt;!--!*#--&gt;Hi:&lt;BR /&gt;&lt;BR /&gt;Whatever you do, don't rely on a 'grep' of the process table to select processes by name.  The UNIX95 (XPG4) option with 'ps' allows you to select a process by its basename, thereby eliminating false matches.&lt;BR /&gt;&lt;BR /&gt;This would work.  Change the value of NAME to match your process.&lt;BR /&gt;&lt;BR /&gt;# cat ./monitor&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;NAME=sleep&lt;BR /&gt;PID=`UNIX95= ps -C ${NAME} -o pid=`&lt;BR /&gt;while [ ! -z "${PID}" ]&lt;BR /&gt;do&lt;BR /&gt;    PID=`UNIX95= ps -C ${NAME} -o pid=`&lt;BR /&gt;    if [ -z "${PID}" ]; then&lt;BR /&gt;        break&lt;BR /&gt;    else&lt;BR /&gt;        echo "alive!"&lt;BR /&gt;        sleep 5&lt;BR /&gt;    fi&lt;BR /&gt;done&lt;BR /&gt;echo "exiting..."&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Nov 2006 11:05:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015778#M96718</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-11-27T11:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015779#M96719</link>
      <description>Bear in mind that even if you use the XPG4 behavior of ps to allow the use of the -C argument that it is still possible to have multiple instances of the same program running. For example (and it's a dumb example), consider running two instances of vi on the same text file. Everything looks identical so which vi do you really want to monitor? I would turn the world around a bit and let the monitor script actually start the process and then use the kill -0 command to check for the existance of the process. &lt;BR /&gt;&lt;BR /&gt;Something like this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;typeset -i PROC_PID=0&lt;BR /&gt;typeset -i KILL_STAT=0&lt;BR /&gt;&lt;BR /&gt;typeset MY_PROC=/xxx/yyy/zzz.exe # the process to start and monitor&lt;BR /&gt;&lt;BR /&gt;${MY_PROC} &amp;amp; # start in background&lt;BR /&gt;PROC_PID=${!} # capture its PID&lt;BR /&gt;while [[ ${KILL_STAT} -eq 0 ]]&lt;BR /&gt;  do&lt;BR /&gt;     kill -0 ${PROC_PID} 2&amp;gt;/dev/null&lt;BR /&gt;     KILL_STAT=${?}&lt;BR /&gt;     if [[ ${KILL_STAT} -eq 0 ]]&lt;BR /&gt;       then&lt;BR /&gt;         sleep 10&lt;BR /&gt;       else&lt;BR /&gt;         echo "Process ${PROC_PID} has terminated."&lt;BR /&gt;       fi&lt;BR /&gt;  done&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;kill -0 PID returns a zero exit status if PID is a valid process ID and non-zero if not.&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Nov 2006 11:40:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015779#M96719</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-11-27T11:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015780#M96720</link>
      <description>Well the grep issue is not that issue for me.&lt;BR /&gt;I need to start a command to list the batchpocesses of a program and based on that output i have to check if a specific batchprocess is still running or finished.&lt;BR /&gt;&lt;BR /&gt;Sorry for the misslead with the line ps -ef but i had to think of a simple exsample to point my problem.&lt;BR /&gt;&lt;BR /&gt;My real problem is, before the backup of a program i have to start a triggerprogram for the batchprocesses within the application to stop (not at or cron).&lt;BR /&gt;But this program is also a batch program so i have to wait till this program kicks-in and does it's work and after the last program exits the batch the backup script must continue with the actual backup.&lt;BR /&gt;&lt;BR /&gt;So i have to wait for a program with a delay to shut down other programs with a delay, and how big that delay is i do'nt now and i get no reply if the programs are finished or not.&lt;BR /&gt;The only thing i have is a list of currently running batch processes.&lt;BR /&gt;Do i have to be original on this or not . . . &lt;BR /&gt;&lt;BR /&gt;Well, Jeff's solution helped me so far, tomorrow i'll know more.&lt;BR /&gt;&lt;BR /&gt;Thanks for the replies.</description>
      <pubDate>Mon, 27 Nov 2006 11:47:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015780#M96720</guid>
      <dc:creator>Klaas D. Eenkhoorn</dc:creator>
      <dc:date>2006-11-27T11:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015781#M96721</link>
      <description>This is a common problem but in a production environment, I would not allow no-status programs to run like that. The whole concept of semaphores, or status files eliminates the large uncertainty in monitoring programs like this. The usual solution is to wait longer than the normal completion time (completely undependable). The next is to watch the programs go away as in your example. But what if the program(s) crash, or are killed or do not run correctly?&lt;BR /&gt; &lt;BR /&gt;I would strongly recommend that the other process(es) be rewritten to report an exit status, perhaps through a simple text file. And the monitoring script needs to perform a sanity check in case no completion file is created after several hours.&lt;BR /&gt; &lt;BR /&gt;If you write code with the idea that everything is going to fail, you won't be disappointed.</description>
      <pubDate>Mon, 27 Nov 2006 23:08:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015781#M96721</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2006-11-27T23:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015782#M96722</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;as mentioned by Bill above, you should ensure that the programs returns an exit status and all you have to do is write a notification programs that informs you. Can be a mail notification or just modification of a status file or table column in a database.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;SCRIPT_STATUS=`&lt;YOURSCRIPT&gt;&lt;/YOURSCRIPT&gt;&lt;BR /&gt;if [ "$SCRIPT_STATUS" != "SUCCESSFUL" ]&lt;BR /&gt;then&lt;BR /&gt;    echo "Error running script &amp;lt;script name&amp;gt;"|mailx -s "error notification" youraddress@domain.mu    &lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;hope this helps too!&lt;BR /&gt;kind regards&lt;BR /&gt;yogeeraj&lt;BR /&gt;</description>
      <pubDate>Mon, 27 Nov 2006 23:56:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015782#M96722</guid>
      <dc:creator>Yogeeraj_1</dc:creator>
      <dc:date>2006-11-27T23:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015783#M96723</link>
      <description>Well Bill you ar right but the writers of the application did not build any status replies outide the application for batchjobs other than in the application itself.&lt;BR /&gt;Outside the applications you can not tell if or how the batchjob ended.&lt;BR /&gt;There is only a fuction to view a list of current processes of the application.&lt;BR /&gt;&lt;BR /&gt;Probably there would be a way to digg in the oracle database underneath to see what batchjobs are running and if they are finished but i'm no oracle guru.&lt;BR /&gt;&lt;BR /&gt;There solution was to stop the batchjobs  with the trigger program from cron for lets say 10 minutes in advance of the backup and if this was not sufficient i had to increase that time.&lt;BR /&gt;That option is mot acceptable for me because the batchprogram supplies information to otherprograms like SAP and that would mean that these SAP applications can also not be used during that time.&lt;BR /&gt;&lt;BR /&gt;Well last night all seemd to go well so i'll see what happns tonight.&lt;BR /&gt;&lt;BR /&gt;Klaas</description>
      <pubDate>Tue, 28 Nov 2006 05:37:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015783#M96723</guid>
      <dc:creator>Klaas D. Eenkhoorn</dc:creator>
      <dc:date>2006-11-28T05:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015784#M96724</link>
      <description>Klaas,&lt;BR /&gt;could you please update the thread with the result of your overnight run. &lt;BR /&gt;&lt;BR /&gt;Another idea I had was to use the wait command to wait for the completion of a specific process before the next process starts.&lt;BR /&gt;</description>
      <pubDate>Wed, 29 Nov 2006 03:54:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015784#M96724</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-11-29T03:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015785#M96725</link>
      <description>It worked, the process is correctly monitored and the script continues after wards.&lt;BR /&gt;&lt;BR /&gt;Thanks for the help !&lt;BR /&gt;&lt;BR /&gt;Kl@@s</description>
      <pubDate>Fri, 01 Dec 2006 04:46:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015785#M96725</guid>
      <dc:creator>Klaas D. Eenkhoorn</dc:creator>
      <dc:date>2006-12-01T04:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need to monitor the existance of a process</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015786#M96726</link>
      <description>&lt;!--!*#--&gt;This works:&lt;BR /&gt;&lt;BR /&gt;print_msg "Stopping Production"&lt;BR /&gt;su - user -c '${TSAPPLROOT}/bin/startcronjob ${TSAPPLROOT} SERVICE'&lt;BR /&gt;if [ $? -eq 0 ]&lt;BR /&gt;  then&lt;BR /&gt;    print_msg "Stop Production scheduled succesfully"&lt;BR /&gt;  else&lt;BR /&gt;    print_msg "Stop Production scheduling failed"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;print_msg "Waiting for Production to finish ..."&lt;BR /&gt;&lt;BR /&gt;TIMEOUT=180 # 3 Minutes time-out&lt;BR /&gt;FOUND=1&lt;BR /&gt;while  [ $FOUND -ne 0 ]&lt;BR /&gt;do&lt;BR /&gt;   FOUND=`/usr/bin/su - user -c showcom | /usr/bin/grep SERVICE | /usr/bin/wc -l`&lt;BR /&gt;   sleep 2&lt;BR /&gt;   echo $FOUND&lt;BR /&gt;   if [ ${TIMEOUT} -le "0" ]&lt;BR /&gt;     then&lt;BR /&gt;        echo "Timed-out"&lt;BR /&gt;        FOUND=0&lt;BR /&gt;     else&lt;BR /&gt;        TIMEOUT=`expr ${TIMEOUT} - 1`&lt;BR /&gt;   fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Fri, 01 Dec 2006 04:57:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-to-monitor-the-existance-of-a-process/m-p/5015786#M96726</guid>
      <dc:creator>Klaas D. Eenkhoorn</dc:creator>
      <dc:date>2006-12-01T04:57:25Z</dc:date>
    </item>
  </channel>
</rss>

