ara.t.howard wrote:
> On Jun 2, 2008, at 11:36 AM, Mrio Lopes 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.
> 
> you need interject another process:
> 
> #
> # Start main process
> #  Start system/child process
> #    INT signals can't stop whatever the system call is doing
> #  End system/child process
> #  If INT signal detected, exit, otherwise, continue running
> # End main process
> #
> 
> def system_critical command
>    signaled = false
>    int = trap('INT'){ puts "signaled #{ $$ }"; signaled = true }
>    begin
>      pid = fork{ system command }
>      Process.kill 'INT', pid
>      Process.waitpid pid
>    ensure
>      trap('INT', int)
>    end
>    exit 15 if signaled
> end
> 
> 
> # use thread just so we can run *and* send ourselves a signal
> 
> thread = Thread.new do
>    system_critical "ruby -e' sleep 1 and puts :done' "
> end
> 
> Process.kill 'INT', Process.pid
> 
> thread.join
> 
> cfp:~ > ruby a.rb
> signaled 25656
> signaled 25657
> done
> 
> 
> cfp:~ > ruby a.rb
> signaled 25660
> signaled 25661
> done

This seems to work fine with sleep 10 ¡½ it waits until the end of the 
execution without actually passing the INT signal! But I'm unable to 
make it work with an external application like ffmpeg that traps the 
SIGINT itself. Any idea on how could I override this behavior without 
having to actually recompile ffmpeg and disable myself the handle?

Thanks again for your help.

Mário
-- 
Posted via http://www.ruby-forum.com/.