[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

determining if a process is alive on windows

ara.t.howard

10/3/2007 3:11:00 PM


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://draw...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




4 Answers

Gordon Thiesfeld

10/3/2007 3:31:00 PM

0

On 10/3/07, ara.t.howard <ara.t.howard@gmail.com> 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://draw...

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

Adam Shelly

10/3/2007 5:27:00 PM

0

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, 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

ara.t.howard

10/3/2007 11:09:00 PM

0


On Oct 3, 2007, at 11:27 AM, Adam Shelly 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://draw...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




ara.t.howard

10/3/2007 11:10:00 PM

0


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

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

well i'll be!

thanks a bunch.

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