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/

On 10/3/07, ara.t.howard [email protected] wrote:

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 [email protected] wrote:

#–}}}
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, 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 Oct 3, 2007, at 9:31 AM, Gordon T. wrote:

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

well i’ll be!

thanks a bunch.

a @ http://drawohara.com/

On Oct 3, 2007, at 11:27 AM, Adam S. wrote:

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/