I am trying to understand how signal handlers attach to a process and their scope for a process.
class Main
Signal.trap('USR1') do
Process2.kill
end
def main_process
#do something
p = Process2.new
output = p.give_output
#then again do something
end
end
class Process2
Signal.trap('USR1') do
Process2.kill
end
def self.kill
if @@static_object.blank?
#do nothing
else
#do something
end
end
def give_output
#do something
@@static_object = true
#do something
end
end
Now if I issue a SIGUSR1
to the process while give_output
is getting executed and @@static_object
is not nil, the handler should behave as expected. However, even after give_output
has finished execution, if a signal is sent, the handler inside Process2
will catch it. From what I understand, the handler gets attached to the process. Can we have two signal handlers for the same process for the same signal? For example - while give_output
is executing and a signal is issued, the handler inside Process2
should get control otherwise another signal handler defined in Main
should get control.