Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Handling two signal handler

Reply
Thread Tools

Handling two signal handler

 
 
sanjeeb
Guest
Posts: n/a
 
      11-19-2009
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???
 
Reply With Quote
 
 
 
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      11-19-2009
sanjeeb <> wrote:
> 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
--
\ Jens Thoms Toerring ___
\__________________________ http://toerring.de
 
Reply With Quote
 
 
 
 
sanjeeb
Guest
Posts: n/a
 
      11-20-2009
On Nov 19, 10:24*pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> sanjeeb <sanjee...@gmail.com> wrote:
> > 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
> --
> * \ * Jens Thoms Toerring *___ * * *j...@toerring.de
> * *\__________________________ * * *http://toerring.de


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.

 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      11-20-2009
On Thu, 19 Nov 2009 22:10:31 -0800, sanjeeb wrote:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
signal handling and (structured) exception handling Peter C++ 34 10-17-2009 10:03 AM
How does a handler render the request to another handler in the MVC of SPRING 2.0.1 framework? rayzyang@gmail.com Java 0 05-30-2007 11:28 AM
Event Handler that creates adds another event handler kaczmar2@gmail.com ASP .Net 1 02-22-2007 07:37 AM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Re: JNI calls from inside UNIX signal handler Joseph Millar Java 5 07-10-2003 04:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57