On Monday, June 02, 2008, at 01:40PM, "Mio Lopes" <mario.lopes / gmail.com> wrote:
>
>What I'm precisely trying to do is trapping the SIGINT signal from 
>getting to the child so it doesn't abort. I've been unable to do this. I 
>can get it on the main process though but can't prevent it from being 
>relayed to the child process.

Does this code demonstrate what you are looking for?  If
you send an interrupt it should be caught by the main ruby process
and ignored by the child processes.

The  code below arranges for the child processes to ignore the INT signal.

If you want to arrange for the child process to not even receive the
signal it gets more complicated.  You've got to arrange for the child
process to be within its own process group and you have to make
sure that process group is detached from the terminal (has no
controlling terminal).  These concerns typically arise when you are
trying to instantiate a daemon process.   Even when you do that
someone can explicitly send the INT signal to your process (assuming
they have permissions).

Anyway, here is the code for the simple case of ignoring the INT signal:

puts "main: #{$$}"
trap('INT') { puts 'int caught by main' }
fork {
    trap 'INT', 'IGNORE'   # forked process ignores INT
    puts "child before sleep: #{$$}"
    exec 'echo "exec command"; sleep 10; echo "exec command after sleep" '
    puts "child after sleep: #{$$}"
  }

puts 'main program after fork'
Process.wait