LinuxSA Mailing list archives

Index: [thread] [date] [subject] [author] [stats]
  From: David Newall <davidn@rebel.net.au>
  To  : Horst Poehlmann <Horst.Poehlmann@pobox.com>
  Date: Fri, 29 Jun 2001 15:33:49 +0930 (CST)

Re: ps and processes

> I run a program that monitors if a process is still running.

You're doing it wrong.  You're probably doing it like this:

  bash$ cat startjobs
  perl /usr/bin/swatch ... &
  per /usr/ bin/swatch ... &

  bash$ cat monitorjobs
  PID=`ps axuw|grep -v grep|grep '/usr/bin/swatch'|cut -f2`
  [ -z "$PID" ] && {
    # process has died
  }

You should be doing it like this:

  bash$ cat startjobs
  monitorjob perl /usr/sbin/swatch ... &
  monitorjob perl /usr/sbin/swatch ... &

  bash$ cat monitorjob
  exec "$@"
  # process has died

  or, to autorestart the job:

  bash$ cat monitorjob
  while :
  do
    exec "$@"
    # process has died
  done

shar and enjoy! (as they used to say.)

-- 
LinuxSA WWW: http://www.linuxsa.org.au/  IRC: #linuxsa on irc.linux.org.au
To unsubscribe from the LinuxSA list:
  mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject


Index: [thread] [date] [subject] [author] [stats]
Return to the LinuxSA Mailing List Information Page