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                    `------------------------------'