------=_NextPart_000_00DB_01CBFA8E.9CB5EEE0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

I have now tried both fork and spawn, and my confusion have reached new
levels. :-)

Fork and ruby
=============
Worked as a charm. Too bad I need to use jruby due to JMX dependencies.


Fork and jruby
==============
Fork seems to be considered dangerous when used in jruby. I have found info
about enabling it, but are having very limited success in doing that.

I have started jirb two ways:

1. jirb -J-Djruby.fork.enabled=true

Results in "IRB::UnrecognizedSwitch: Unrecognized switch:
-J-Djruby.fork.enabled=true"

2. jruby -J-Djruby.fork.enabled=true -S jirb

Results in "NotImplementedError: fork is not available on this platform".

The jruby.fork.enabled property isn't listed when I do jruby --properties
either. Has it been removed?


Spawn and jruby
===============
1. Process.spawn("xeyes")
Do not protect the spawned process from Ctrl-C.

2. Process.spawn("xeyes", :pgroup=>true)
Gives the xeyes usage message; the option is used as a part of the command.
How do jruby separates options for the command and options for
Process.spawn?

Just to test that I read the Rdoc page for Process right:

3. spawn({"FOO"=>"BAR", "BAZ"=>nil}, "xeyes")
Errno::ENOENT: No such file or directory - {"FOO"=>"BAR", "BAZ"=>nil}


///Best regards, Jens Carlberg

-----Original Message-----
From: Charles Oliver Nutter [mailto:headius / headius.com] 
Sent: den 11 april 2011 01:32
To: ruby-talk / ruby-lang.org
Cc: Jens Carlberg
Subject: Re: How do I trap Ctrl-C so it doesn't reach spawned threads?

On Fri, Apr 8, 2011 at 2:53 AM, Jens Carlberg <jens.carlberg / ericsson.com>
wrote:
> Hi!
>
> I'm having trouble trapping Ctrl-C. I have a CLI that spawns processes I
would like to survive the CLI, but if I press Ctrl-C the spawns dies along
with the CLI. I have experimented with trap(INT), and have boiled down the
problem into a small example program. I run this on Linux.
...
> I don't understand the behaviour. The jruby version feels more consistent,
but is far away from what I need. The ruby version feels strange, but I
could handle my needs by spawning a dummy process if I didn't need jmx4r
(which as far as I understand requires jruby).
>
> 1. How is trapping of SIGINT supposed to work? How is the passing of
SIGINT supposed to work?
> 2. Why does it differs between ruby and jruby?
> 3. Anyone with a suggestion how to spawn processes not affected by a
SIGINT?

In MRI, I *believe* SIGINT is sent to the process that currently controls
the TTY, so in the case of system() it's sent to your program that's
running.

In JRuby, child processes don't usually share the TTY streams (JVM isolates
child process streams from the parent using pipes), so Ctrl-C is sent to
JRuby (the JVM itself, really, since we don't trap INT in JRuby and allow
JVM to handle it) and it shuts down taking the active child process with it.

Perhaps you can try to use posix_spawn or 1.9's "spawn"?

- Charlie

------=_NextPart_000_00DB_01CBFA8E.9CB5EEE0
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIQUzCCA2Ew
ggJJoAMCAQICEAoBAQEAAAJ8AAAACgAAAAIwDQYJKoZIhvcNAQEFBQAwOjEZMBcGA1UEChMQUlNB
IFNlY3VyaXR5IEluYzEdMBsGA1UECxMUUlNBIFNlY3VyaXR5IDIwNDggVjMwHhcNMDEwMjIyMjAz
OTIzWhcNMjYwMjIyMjAzOTIzWjA6MRkwFwYDVQQKExBSU0EgU2VjdXJpdHkgSW5jMR0wGwYDVQQL
ExRSU0EgU2VjdXJpdHkgMjA0OCBWMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALeP
VXHSgN17aXmn8BhQMjxiZ/YKlQfd5hvzntnSQVRrrZ98vhnN+0arQWgeGOpVyC+ReIko+ycpYP/f
j4w7yUmbtaSUzgHqPrVje38m/RndwCG9hNEtT0bDTtzYNzk7KK/LnRrqK68hpcEjIri4G1oTh1eD
0fAg5+hPI0KwAKV9ienpYXOUmHEmvC1q4PdN8PG2KjgxgQ0p4QDBUQ9MUvgEWqp9ctO4hyq7YxAD
KrOhTw1aXka3PQ71dOyZn/k9JIGIpt1gVOiVNj3GCZOaoxKAAFWZGUe90KV8w7r7H/f1D/isubX0
N5gTGN6FW7cMg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