# Determining if a process is alive on windows

**URL:** <https://www.ruby-forum.com/t/determining-if-a-process-is-alive-on-windows/116226>\
**Category:** Ruby\
**Created:** [October 3, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/determining-if-a-process-is-alive-on-windows/116226 "2007-10-03T17:11:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [October 3, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/determining-if-a-process-is-alive-on-windows/116226/1 "2007-10-03T17:11:39Z")

</div>

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/](http://drawohara.com/)

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [October 3, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/determining-if-a-process-is-alive-on-windows/116226/2 "2007-10-03T17:31:36Z")

</div>

On 10/3/07, ara.t.howard [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](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

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [October 3, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/determining-if-a-process-is-alive-on-windows/116226/3 "2007-10-03T19:27:53Z")

</div>

On 10/3/07, ara.t.howard [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [October 4, 2007, 1:11am UTC](https://www.ruby-forum.com/t/determining-if-a-process-is-alive-on-windows/116226/4 "2007-10-04T01:11:53Z")

</div>

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/](http://drawohara.com/)

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [October 4, 2007, 1:10am UTC](https://www.ruby-forum.com/t/determining-if-a-process-is-alive-on-windows/116226/5 "2007-10-04T01:10:42Z")

</div>

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/](http://drawohara.com/)
