Handling two signal handler

S

sanjeeb

Hi,
I have a application which multiple modules. Each module do some task.
I have a signal handler defined in the main.pl which is the starting
point to run the application.
I want to define signal handler in each module which will do specific
task and again raised a signal which will be handled by the global
signal handler.
The signal to be caught are same throughout, not specific to any class
or the global handler.
Scenario :
application.pl define a a signal handler &globalhandler
application.pl creates a object out of foo.pm and foo.pm defines
a handle &foo_cleaner
when the execution is under the context of foo.pm object , a
INT signal caught. It will clean up the required things populated
by foo.pm and then raised the same signal from foo_cleaner. After
raising the &globalhandler should be called means the global handler
will be caught.
I tried but didnt succeded.

Do you have guys any idea whether there is some way out???
Can i get two handlers with the same signal???
 
J

Jens Thoms Toerring

sanjeeb said:
I have a application which multiple modules. Each module do some task.
I have a signal handler defined in the main.pl which is the starting
point to run the application.
I want to define signal handler in each module which will do specific
task and again raised a signal which will be handled by the global
signal handler.
The signal to be caught are same throughout, not specific to any class
or the global handler.
Scenario :
application.pl define a a signal handler &globalhandler
application.pl creates a object out of foo.pm and foo.pm defines
a handle &foo_cleaner
when the execution is under the context of foo.pm object , a

What do you mean with "the context of foo.pm object"?
INT signal caught. It will clean up the required things populated
by foo.pm and then raised the same signal from foo_cleaner. After
raising the &globalhandler should be called means the global handler
will be caught.
I tried but didnt succeded.
Do you have guys any idea whether there is some way out???
Can i get two handlers with the same signal???

You can have only a single signal handler for each signal. So
if the signal has been dealt with by foo_cleaner() then it's
used up. Raising it again would only lead to foo_cleaner() being
called again as long as it's still installed as the handler for
that signal.

What you can do is to simply call global_handler() from
foo_cleaner(). You can figure out its address by inspecting
the value of $SIG{INT} before you install foo_cleaner() as
the new signal handler. I.e. do

my $old_handler = $SIG{ INT };
$SIG{ INT } = \&new_handler;

sub new_handler {
do_something;
&$old_handler( @_ );
}
Regards, Jens
 
S

sanjeeb

What do you mean with "the context of foo.pm object"?


You can have only a single signal handler for each signal. So
if the signal has been dealt with by foo_cleaner() then it's
used up. Raising it again would only lead to foo_cleaner() being
called again as long as it's still installed as the handler for
that signal.

What you can do is to simply call global_handler() from
foo_cleaner(). You can figure out its address by inspecting
the value of $SIG{INT} before you install foo_cleaner() as
the new signal handler. I.e. do

my $old_handler = $SIG{ INT };
$SIG{ INT } = \&new_handler;

sub new_handler {
    do_something;
    &$old_handler( @_ );}

                             Regards, Jens

Thanks.
I tried this before but it is not working in a threaded environment.
In context means , the object is created in a thread, but the signal
handler is installed at the
main application. Here is the flow.
../main.pl creates a thread -> object of Execution.pm is created in the
thread -> The signal handler should be installed in this context when
the thread created the object of Execution.pm.

i am hunting for the solution, let me know if you found anything,
thanks.
 
M

Martijn Lievaart

I tried this before but it is not working in a threaded environment. In
context means , the object is created in a thread, but the signal
handler is installed at the
main application. Here is the flow.
./main.pl creates a thread -> object of Execution.pm is created in the
thread -> The signal handler should be installed in this context when
the thread created the object of Execution.pm.

i am hunting for the solution, let me know if you found anything,
thanks.

Threads and signals don't mix, as noted in the threads documentation.
This makes Perl threads absolutely useless in my opinion. Try a fork
based solution instead.

M4
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top