fork() function is unimplemented on this machine

R

Ralph Shnelvar

[Note: parts of this message were removed to make it a legal post.]

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?
 
C

Chuck Remes

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?

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
 
J

Joel VanderWerf

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
 
R

Ralph Shnelvar

[Note: parts of this message were removed to make it a legal post.]

Joel,

Monday, August 30, 2010, 12:00:00 PM, you wrote:


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!
 
R

Robert Klemme

Monday, August 30, 2010, 12:00:00 PM, you wrote:



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.

Another solution is to use cygwin which does support fork().

Kind regards

robert
 
J

Jörg W Mittag

Ralph said:
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?

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 Matsumoto 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top