Determining if a process is alive on windows

on *nix i use this

···

#
# 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
   export 'alive', 'alive?'

i expect it won't work on windows but maybe i'm wrong? if so can someone suggest code to accomplish this task?

cheers.

a @ http://drawohara.com/
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

i expect it won't work on windows but maybe i'm wrong? if so can
someone suggest code to accomplish this task?

cheers.

a @ http://drawohara.com/

It works for me on Windows XP, with the Ruby 1.86 OCI.

alive?(6012) # firefox

=> true

alive?(5352) # task manager

=> true

alive?(6000) # doesn't exist

=> false

regards,

Gordon

···

On 10/3/07, ara.t.howard <ara.t.howard@gmail.com> wrote:

It works for me on windows too, but I've got 2 questions:

I get "undefined method `export' for main:Object (NoMethodError)"
What does export do? Where is it defined?

And what are these comments for?
#---{{{
#---}}}

thanks,
-Adam

···

On 10/3/07, ara.t.howard <ara.t.howard@gmail.com> wrote:

#
  def alive pid
#--{{{
    pid = Integer("#{ pid }")
    begin
      Process::kill 0, pid
      true
    rescue Errno::ESRCH
      false
    end
#--}}}
  end
  alias alive? alive
  export 'alive', 'alive?'

i expect it won't work on windows but maybe i'm wrong? if so can
someone suggest code to accomplish this task?

It works for me on windows too,

thanks!

but I've got 2 questions:

I get "undefined method `export' for main:Object (NoMethodError)"
What does export do? Where is it defined?

it's in alib:

   module Util
     def self.export *syms
       syms.each do |sym|
         module_function sym
         public sym
       end
     end
   end

And what are these comments for?
#---{{{
#---}}}

the #{{{ and #}}} mark folds in vim so, to me, all that code is one line. the leading --- keeps rdoc from choking on them. cheers.

a @ http://drawohara.com/

···

On Oct 3, 2007, at 11:27 AM, Adam Shelly wrote:
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

well i'll be!

thanks a bunch.

a @ http://drawohara.com/

···

On Oct 3, 2007, at 9:31 AM, Gordon Thiesfeld wrote:

It works for me on Windows XP, with the Ruby 1.86 OCI.

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama