On Wed, 15 Jun 2005, nobuyoshi nakada wrote:

> You should give a chance to terminate gently to the child process, I
> guess.
>
>>        Process::kill 'KILL', pid rescue nil

yes, very true.  in 'real-life' the code from my lib is

   module Util
     #
     # returns true if pid is running, false otherwise
     #
       def alive pid
#--{{

         pid = Integer("#{ pid }")
         begin
           Process::kill 0, pid
           true
         rescue Errno::ESRCH
           false
         end
#--}}}
       end
       alias alive? alive
     #
     # brutally shut down a process.  opts can contain the keys 'signals' which
     # should be a list of signals used to send to the process and the key
     # 'suspend' which is the amount of time to wait after firing each signal
     # before seeing if the process is dead.  the defaults are %w(TERM QUIT KILL)
     # and 4 respectively
     #
       def maim(pid, opts = {})
#--{{{
         sigs = Util::getopt 'signals', opts, %w(SIGTERM SIGQUIT SIGKILL)
         suspend = Util::getopt 'suspend', opts, 4
         pid = Integer("#{ pid }")
         existed = false
         sigs.each do |sig|
           begin
             Process::kill(sig, pid)
             existed = true
           rescue Errno::ESRCH
             unless existed
               return nil
             else
               return true
             end
           end
           sleep 0.1
           return true unless Util::alive?(pid)
           sleep suspend
           return true unless Util::alive?(pid)
         end
         return(not alive?(pid))
#--}}}
       end
     #
     # look up key in hash as key, then string of key, then intern of key -
     # returning the value or, if key is not found, nil or default
     #
       def getopt opt, hash, default = nil
#--{{{
         key = opt
         return hash[key] if hash.has_key? key
         key = "#{ key }"
         return hash[key] if hash.has_key? key
         key = key.intern
         return hash[key] if hash.has_key? key
         return default
#--}}}
       end
     end


but that's not so nice to post ;-)

-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| My religion is very simple.  My religion is kindness.
| --Tenzin Gyatso
===============================================================================