[#4341] DRY and embedded docs. — Hugh Sasse Staff Elec Eng <hgs@...>
If I have a here document in some ruby program:
[#4347] Re: DATA and rewind. — ts <decoux@...>
>>>>> "H" == Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:
[#4350] Re: Thirty-seven Reasons [Hal Fulton] Love[s] Ruby — "David Douthitt" <DDouthitt@...>
[#4396] Re: New Require (was: RAA development ideas (was: RE: Looking for inp ut on a 'links' page)) — Hugh Sasse Staff Elec Eng <hgs@...>
On 9 Aug 2000, Dave Thomas wrote:
[#4411] Re: RAA development ideas (was: RE: Lookin g for inp ut on a 'links' page) — Aleksi Niemel<aleksi.niemela@...>
Me:
On Thu, 10 Aug 2000, [iso-8859-1] Aleksi Niemelwrote:
[#4465] More RubyUnit questions. — Hugh Sasse Staff Elec Eng <hgs@...>
I am beginning to get a feel for this, but I still have a few more
[#4478] Re: RubyUnit. Warnings to be expected? — ts <decoux@...>
>>>>> "H" == Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:
[#4481] Invoking an extension after compilation — Dave Thomas <Dave@...>
Hi,
[#4501] What's the biggest Ruby development? — Dave Thomas <Dave@...>
[#4502] methods w/ ! giving nil — Hugh Sasse Staff Elec Eng <hgs@...>
I have got used to the idea that methods that end in '!' return nil if
[#4503] RubyUnit and encapsulation. — Hugh Sasse Staff Elec Eng <hgs@...>
My_class's instance variables are not all "attr :<name>" type variables,
[#4537] Process.wait bug + fix — Brian Fundakowski Feldman <green@...>
If your system uses the rb_waitpid() codepath of rb_f_wait(),
[#4567] Re: What's the biggest Ruby development? — Aleksi Niemel<aleksi.niemela@...>
Dave said:
Robert Feldt <feldt@ce.chalmers.se> writes:
On Sat, 26 Aug 2000, Dave Thomas wrote:
Robert Feldt <feldt@ce.chalmers.se> writes:
On Mon, 28 Aug 2000, Dave Thomas wrote:
Robert Feldt <feldt@ce.chalmers.se> writes:
[#4591] Can't get Tcl/Tk working — Stephen White <steve@...>
I can't get any of the samples in the ext/tk/sample directory working. All
I'm sure looking forwards to buying the book. :)
Stephen White <steve@deaf.org> writes:
On Sun, 27 Aug 2000, Dave Thomas wrote:
Stephen White <steve@deaf.org> writes:
[#4608] Class methods — Mark Slagell <ms@...>
Reading the thread about regexp matches made me wonder about this:
[#4611] mod_ruby 0.1.19 — shreeve@...2s.org (Steve Shreeve)
Shugo (and others),
[#4633] Printing tables — DaVinci <bombadil@...>
Hi.
[#4647] Function argument lists in parentheses? — Toby Hutton <thutton@...>
Hello,
[#4652] Andy and Dave's European Tour 2000 — Dave Thomas <Dave@...>
Hi,
[#4672] calling super from c — Robert Feldt <feldt@...>
[#4699] Double parenthesis — Klaus Spreckelsen <ks@...1.ruhr-uni-bochum.de>
Why is the first line ok, but the second line is not?
[ruby-talk:4557] New feature: Process.waitall
Okay, I figured that I wanted a new routine that really had all of the
semantics I thought were useful :) Also, I needed the W* functions.
Check this out:
irb(main):001:0> (0..4).each {|c| fork { sleep 1 + 2 * c; exit c}}
0..4
irb(main):002:0> x = Process.waitall
[[34040, 0], [34041, 256], [34042, 512], [34043, 768], [34044, 1024]]
irb(main):003:0> x.each {|p| p Process.wexitstatus p[1]}
0
1
2
3
4
[[34040, 0], [34041, 256], [34042, 512], [34043, 768], [34044, 1024]]
Neat? :)
I've included the implementation (in diff -u format). I've not tested
the NO_WAITPID case since I don't have a "no waitpid" machine, but I
think I did the code correctly for that.
--
Brian Fundakowski Feldman \ FreeBSD: The Power to Serve! /
green@FreeBSD.org `------------------------------'
Attachments (1)
--- process.c.orig Mon Jul 24 03:16:13 2000
+++ process.c Tue Aug 22 22:24:57 2000
@@ -157,6 +157,30 @@
data->status = value;
return ST_DELETE;
}
+
+struct waitall_data {
+ int pid;
+ int status;
+ VALUE ary;
+}
+
+static int
+waitall_each(key, value, data)
+ int key, value;
+ struct wait_data *data;
+{
+ VALUE pid_status_member;
+
+ if (data->status != -1) return ST_STOP;
+
+ data->pid = key;
+ data->status = value;
+ pid_status_member = rb_ary_new2(2);
+ rb_ary_push(pid_status_member, INT2NUM(key));
+ rb_ary_push(pid_status_member, INT2NUM(value));
+ rb_ary_push(data->ary, pid_status_member);
+ return ST_DELETE;
+}
#endif
static VALUE
@@ -189,6 +213,58 @@
}
static VALUE
+rb_f_waitall()
+{
+ VALUE pid_status_ary, pid_status_member;
+ int pid, state;
+#ifdef NO_WAITPID
+ struct waitall_data data;
+
+ data.ary = pid_status_ary = rb_ary_new();
+ data.status = -1;
+ st_foreach(pid_tbl, waitall_each, &data);
+ if (data.status != -1) {
+ rb_last_status = data.status;
+ return pid_status_ary;
+ }
+
+ for (pid = -1;;) {
+ pid = wait(&state);
+ if (pid == -1) {
+ if (errno == ECHILD)
+ break;
+ if (errno == EINTR) {
+ rb_thread_schedule();
+ continue;
+ }
+ rb_sys_fail(0);
+ }
+ pid_status_member = rb_ary_new2(2);
+ rb_ary_push(pid_status_member, INT2NUM(pid));
+ rb_ary_push(pid_status_member, INT2NUM(state));
+ rb_ary_push(pid_status_ary, pid_status_member);
+ }
+ if (RARRAY(pid_status_ary)->len != 0)
+ rb_last_status = INT2FIX(state);
+#else
+ pid_status_ary = rb_ary_new();
+ for (pid = -1;;) {
+ pid = rb_waitpid(-1, 0, &state);
+ if (pid == -1) {
+ if (errno == ECHILD)
+ break;
+ rb_sys_fail(0);
+ }
+ pid_status_member = rb_ary_new2(2);
+ rb_ary_push(pid_status_member, INT2NUM(pid));
+ rb_ary_push(pid_status_member, INT2NUM(state));
+ rb_ary_push(pid_status_ary, pid_status_member);
+ }
+#endif
+ return pid_status_ary;
+}
+
+static VALUE
rb_f_waitpid(obj, vpid, vflags)
VALUE obj, vpid, vflags;
{
@@ -203,6 +279,83 @@
return INT2FIX(pid);
}
+static VALUE
+rb_f_wifstopped(obj, statusnum)
+ VALUE obj, statusnum;
+{
+ int status = NUM2INT(statusnum);
+
+ if (WIFSTOPPED(status))
+ return Qtrue;
+ else
+ return Qfalse;
+}
+
+static VALUE
+rb_f_wstopsig(obj, statusnum)
+ VALUE obj, statusnum;
+{
+ int status = NUM2INT(statusnum);
+
+ return INT2NUM(WSTOPSIG(status));
+}
+
+static VALUE
+rb_f_wifsignaled(obj, statusnum)
+ VALUE obj, statusnum;
+{
+ int status = NUM2INT(statusnum);
+
+ if (WIFSIGNALED(status))
+ return Qtrue;
+ else
+ return Qfalse;
+}
+
+static VALUE
+rb_f_wtermsig(obj, statusnum)
+ VALUE obj, statusnum;
+{
+ int status = NUM2INT(statusnum);
+
+ return INT2NUM(WTERMSIG(status));
+}
+
+static VALUE
+rb_f_wifexited(obj, statusnum)
+ VALUE obj, statusnum;
+{
+ int status = NUM2INT(statusnum);
+
+ if (WIFEXITED(status))
+ return Qtrue;
+ else
+ return Qfalse;
+}
+
+static VALUE
+rb_f_wexitstatus(obj, statusnum)
+ VALUE obj, statusnum;
+{
+ int status = NUM2INT(statusnum);
+
+ return INT2NUM(WEXITSTATUS(status));
+}
+
+#ifdef WCOREDUMP
+static VALUE
+rb_f_wcoredump(obj, statusnum)
+ VALUE obj, statusnum;
+{
+ int status = NUM2INT(statusnum);
+
+ if (WCOREDUMP(status))
+ return Qtrue;
+ else
+ return Qfalse;
+}
+#endif
+
char *strtok();
#ifdef HAVE_SETITIMER
@@ -1053,7 +1206,17 @@
#endif
#ifndef NT
rb_define_module_function(rb_mProcess, "wait", rb_f_wait, 0);
+ rb_define_module_function(rb_mProcess, "waitall", rb_f_waitall, 0);
rb_define_module_function(rb_mProcess, "waitpid", rb_f_waitpid, 2);
+ rb_define_module_function(rb_mProcess, "wifstopped", rb_f_wifstopped, 1);
+ rb_define_module_function(rb_mProcess, "wstopsig", rb_f_wstopsig, 1);
+ rb_define_module_function(rb_mProcess, "wifsignaled", rb_f_wifsignaled, 1);
+ rb_define_module_function(rb_mProcess, "wtermsig", rb_f_wtermsig, 1);
+ rb_define_module_function(rb_mProcess, "wifexited", rb_f_wifexited, 1);
+ rb_define_module_function(rb_mProcess, "wexitstatus", rb_f_wexitstatus, 1);
+#ifdef WCOREDUMP
+ rb_define_module_function(rb_mProcess, "wcoredump", rb_f_wcoredump, 1);
+#endif
#ifndef USE_CWGUSI
rb_define_module_function(rb_mProcess, "pid", get_pid, 0);