The Artima Developer Community
Sponsored Link

Agile Buzz Forum
win32-process quirks

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Kevin Rutherford

Posts: 171
Nickname: spinach
Registered: Apr, 2006

Kevin Rutherford is an independent agile software development coach based in the UK
win32-process quirks Posted: Mar 5, 2007 2:22 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Kevin Rutherford.
Original Post: win32-process quirks
Feed Title: silk and spinach
Feed URL: http://silkandspinach.net/blog/index.xml
Feed Description: kevin rutherford on agile software development and life in macclesfield
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Kevin Rutherford
Latest Posts From silk and spinach

Advertisement

I had occasion to install the win32-process gem today, because my Watir tests needed to start a background agent. On my laptop the cookbook example in the gem's documentation doesn't work; I found:

  • The package to require is 'win32/process';
  • the block version of fork() causes the child process to execute the block and then continue with the parent code;
  • the module names in the examples are incorrect (and not needed); and
  • the return value from Process.create() is not a process ID, but a structure that contains a process ID.

Nothing major, but it wasted twenty minutes. Anyway, for completeness here are a couple of corrected example scripts showing the behaviour of win32-process. First, mimicking the old Unix API:

require "win32/process"

pid = Process.fork
if pid.nil?
  3.times {
    puts "In the child"
    sleep 1
  }
  exit
end

2.times {
  puts "In the parent"
  sleep 1
}

Process.wait

As expected, this produces

In the parent
In the child
In the parent
In the child
In the child

Now try passing a block to the child:

require "win32/process"

Process.fork do
  3.times {
    puts "In the child"
    sleep 1
  }
  exit
end

2.times {
  puts "In the parent"
  sleep 1
}

Process.wait

On my PC this produces:

In the parent
In the child
In the parent
In the child
In the child
In the parent
In the parent

Those extra prints from the parent show that the child process continued after completing the block!

Read: win32-process quirks

Topic: Project Types Previous Topic   Next Topic Topic: Such an Achievement!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use