Common usage imply 5 steps:
SignalHandler
interfaceredef receive_signal_unsafe
to handle sigsegv
redef receive_signal
to handle other signals safely
4, Notify what signals to handle with handle_signal
check_signals
Usage example:
class MyReceiver
super SignalHandler
redef fun receive_signal(signal)
do
print "received safely {signal}"
if signal == sigalarm then print "Alarm!"
end
redef fun receive_signal_unsafe( signal ) do print "received unsafely {signal}"
end
var r = new MyReceiver
# Handle `sigsegv` signal unsafely (the only way for this one)
r.handle_signal(sigsegv, false)
# Handle `sigint` and `sigalarm` safely
r.handle_signal(sigint, true)
r.handle_signal(sigalarm, true)
# Ask system to receive a `sigalarm` signal in 1 second
set_alarm(1)
loop
# Check signals and callback `receive_signal`
var hit = check_signals
if hit then break
end