I am trying to implement the code on page 181 of Programming Ruby 1.9
The code on that page reads
trap(“CLD”) do
pid = Process.wait
puts "Child pid #{pid}: terminated
end
fork { exec(“sort testfile >output.txt”) }
When I attempt to run similar code I first get that
unsupported signal SIGCLD
I tried SIGCHLD … same problem.
Signals.list generates
{“SEGV”=>11, “KILL”=>9, “TERM”=>15, “INT”=>2, “FPE”=>8, “ABRT”=>22,
“ILL”=>4, “EXIT”=>0}
So I next tried
trap(“EXIT”) do
pid = Process.wait
puts "Child pid #{pid}: terminated
end
fork { exec(“sort testfile >output.txt”) }
and that’s when I get the msg
fork() function is unimplemented on this machine
Is fork truly not implemented for 1.8.6 and Windows?
How can I execute (spawn) an external program in 1.8.6 and know when the
program is finished?
here are the various signals for ruby documented?
On Aug 30, 2010, at 11:47 AM, Ralph S. wrote:
So I next tried
fork() function is unimplemented on this machine
Is fork truly not implemented for 1.8.6 and Windows?
As far as I know, Windows does not support fork.
How can I execute (spawn) an external program in 1.8.6 and know when the program is finished?
For one, upgrade to Ruby 1.9.1 or 1.9.2 at minimum. After doing so,
check out Kernel#spawn.
http://ruby-doc.org/ruby-1.9/classes/Kernel.src/M002642.html
This code is supported under Windows.
here are the various signals for ruby documented?
I don’t know.
cr
On 08/30/2010 09:47 AM, Ralph S. wrote:
How can I execute (spawn) an external program in 1.8.6 and know when the program is finished?
t = Thread.new do
system “sleep 1”
end
p t.alive?
sleep 1.5
p t.alive?
p t.value
t.join
On 08/31/2010 01:20 AM, Ralph S. wrote:
JV> sleep 1.5
JV> p t.alive?
JV> p t.value
JV> t.join
May all the gods of all the religions bless your home and your family.
Another solution is to use cygwin which does support fork().
Kind regards
robert
Joel,
Monday, August 30, 2010, 12:00:00 PM, you wrote:
JV> On 08/30/2010 09:47 AM, Ralph S. wrote:
How can I execute (spawn) an external program in 1.8.6 and know when the program is finished?
JV> t = Thread.new do
JV> system “sleep 1”
JV> end
JV> p t.alive?
JV> sleep 1.5
JV> p t.alive?
JV> p t.value
JV> t.join
May all the gods of all the religions bless your home and your family.
Thanks!
Ralph S. wrote:
Is fork truly not implemented for 1.8.6 and Windows?
fork is a POSIX/Unix system call. It is therefore only available on
POSIX/Unix. This does not only apply to Ruby 1.8.6, but to all
versions of Ruby, and it not only applies to Windows, but to all
non-POSIX platforms including, for example, the JVM, the CLI, the
Flash VM or ECMAScript.
This surprised me (and still does) and I would consider this a bug,
but I saw a video of an interview with Yukihiro M. in which he
explained that this is in fact not a bug but a feature. Ruby is
deliberately not intended to be platform-independent, and the fact
that Ruby programs behave differently or don’t work at all when run
on a different operating system or even on the same operating system
and a different CPU is normal and expected.
Note: there are POSIX emulation layers for Windows, such as Cygwin or
Microsoft’s own Services for Unix. However, you will need to build
your execution engine specifically for those platforms if you want to
use them. Also, this doesn’t change the fact that processes in Windows
are used for completely different purposes than processes on Unix, and
thus have substantially different performance characteristics and
behaviors.
[…]
here are the various signals for ruby documented?
Again: those are POSIX signals. Which signals are available on which
platform depends on the platform, so you have to look in your
platform’s manual instead of Ruby’s. In this particular case, I assume
you are using the MinGW port of the MRI Ruby execution engine, so you
will find a list of the supported signals in the MinGW documentation.
(Actually, you probably won’t, since their documentation isn’t
particularly good. You’ll probably have to look through the source
code.)
In particular, the SIGCHILD signal is related to POSIX’s process
model, which doesn’t really apply on Windows.
jwm
All I can say is, if you want it being platform-independent, don’t use
fork.
The idea of forking a process is a typical UNIX-centrism.
(2010/09/01 20:05), Jörg W Mittag wrote:
This surprised me (and still does) and I would consider this a bug,
but I saw a video of an interview with Yukihiro M. in which he
explained that this is in fact not a bug but a feature. Ruby is
deliberately not intended to be platform-independent, and the fact
that Ruby programs behave differently or don’t work at all when run
on a different operating system or even on the same operating system
and a different CPU is normal and expected.
You mean, we should eliminate forking feature from ruby?