From: "ara.t.howard" Date: 2008-06-03T01:07:04+09:00 Subject: Re: Traping signals on child processes On Jun 2, 2008, at 8:59 AM, Mário Lopes wrote: > Hi, > > I currently have a Ruby process that spawns another process through a > system() call in order to run an application from the command line. > The > child process should not be aborted by INT signals and therefore the > parent process shall wait for it to finish before exiting. > > In order to do so I tried trapping the INT signal but since system > runs > in the foreground of the main process it seems that the application > that's being called gets the INT signal nevertheless, despite being > trapped in Ruby. The other approach I took was spawning a process in > the > background and then waiting for it to finish but this approach adds a > lot of complexity due to shared code that can't be run twice. > > What's the best approach to accomplish this? For the sake of > simplicity > I'll leave a very simple example of what I want to do > > 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 > > Any ideas or suggestions to accomplish such are most welcome. > > Thanks, > > Mário trap( :INT ){ warn "can't do that" } fork { exec command } Process.wait if the child installs it's own signal handler you are hosed. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama