[#4567] Re: What's the biggest Ruby development? — Aleksi Niemel<aleksi.niemela@...>

Dave said:

18 messages 2000/08/23
[#4568] Q's on Marshal — Robert Feldt <feldt@...> 2000/08/23

[#4580] RubyUnit testcase run for different init params? — Robert Feldt <feldt@...> 2000/08/25

[#4584] Re: RubyUnit testcase run for different init params? — Dave Thomas <Dave@...> 2000/08/25

Robert Feldt <feldt@ce.chalmers.se> writes:

[#4623] Re: RubyUnit testcase run for different init params? — Robert Feldt <feldt@...> 2000/08/28

On Sat, 26 Aug 2000, Dave Thomas wrote:

[#4652] Andy and Dave's European Tour 2000 — Dave Thomas <Dave@...>

24 messages 2000/08/30
[#4653] Re: Andy and Dave's European Tour 2000 — matz@... (Yukihiro Matsumoto) 2000/08/30

Hi,

[#4657] Ruby tutorials for newbie — Kevin Liang <kevin@...> 2000/08/30

Hi,

[ruby-talk:4537] Process.wait bug + fix

From: Brian Fundakowski Feldman <green@...>
Date: 2000-08-22 04:44:40 UTC
List: ruby-talk #4537
If your system uses the rb_waitpid() codepath of rb_f_wait(),
Process.wait will return prematurely if you have multiple child
processes.  The problem is that rb_waitpid() is called only once,
when it needs to be called until a you get an ECHILD error from
rb_waitpid().

The fix for this is:

--- process.c.orig	Tue Aug 22 00:01:56 2000
+++ process.c	Tue Aug 22 00:14:12 2000
@@ -182,8 +182,21 @@
     }
     rb_last_status = INT2FIX(state);
 #else
-    if ((pid = rb_waitpid(-1, 0, &state)) < 0)
-	rb_sys_fail(0);
+    for (pid = -1;;) {
+	int npid;
+
+	npid = rb_waitpid(-1, 0, &state);
+	if (npid == -1) {
+	    if (errno == EINTR) {
+		rb_thread_schedule();
+		continue;
+	    }
+	    if (errno == ECHILD && pid != -1)
+		break;
+	    rb_sys_fail(0);
+	} else
+	    pid = npid;
+    }
 #endif
     return INT2FIX(pid);
 }

The issue this brings up is that multiple processes can be collected
by Process.wait.  I propose an API change: Process.wait returns an
Array of all of the pids which have been gathered instead of the
last one.  This also brings up whether it should just return [] for
Errno::ECHILD, and also if the same API changes should be made to
Process.waitpid (which collects exit values as well as pids, and can
collect multiple processes at a time.)

I hope I didn't open up too big a can of worms :)

--
 Brian Fundakowski Feldman           \  FreeBSD: The Power to Serve!  /
 green@FreeBSD.org                    `------------------------------'


In This Thread

Prev Next