Run process blocking signals from terminal
If I run ruby script from terminal and run some other process using system
from it and press Ctrl+C, than INT is sent to the other process, how can I make ruby process to handle it and the other process not to get it at all?
Example:
tr开发者_如何学Cap('INT'){ puts 'Wait a bit' }
system 'sleep 100'
If I press Ctrl+C this script will exit immediately and will not print anything: INT will be sent only to sleep, so it will exit and script will be finished.
You might be talking about forking, rather than using system. The section on Independent Children
in Programming Ruby might help.
Or, you might be talking about running the child completely detached from the parent as a standalone app, so that if the parent quits the child continues, like httpd servers and the like. I haven't tried it but Daemons
sounds like it'd work nicely.
You can trap INT
and and exit, using trap("INT") { exit }
. Like Greg, not sure if this is what you wanted, but it might be something to look in to.
精彩评论