Re: Catching a signal

From: Fons Rademakers <Fons.Rademakers_at_cern.ch>
Date: Wed, 26 Jan 2011 17:16:10 +0100


Hi,

   use TApplication::GetSignalHandler() to get the current interrupt handler. Do something like:

    TSignalHandler *ih = gApplication->GetSignalHandler();     ih->Remove();
    MyInterruptHandler *my = new MyInterruptHandler();     my->Add();
    gApplication->SetSignalHandler(my);
    delete ih;

Cheers, Fons.

On 26/01/2011 16:38, Filimon Roukoutakis wrote:
> Hi, my signal hanlder gets called after the normal Rint handler is called
> (the usual *** Break *** keyboard interrupt (tmpfile):1:) and then on all
> subsequent ctrl-c is not called, only the familiar one above. Is this the
> expected behaviour? I would expect that my handler completely replaces the
> existing one. Is it possible to achieve this somehow?
> TSystem::RemoveSignalHandler
> <http://root.cern.ch/root/html/TSystem.html#TSystem:RemoveSignalHandler>()
> would require the original object (not in my scope) and searching through
> TSystem::GetListOfSignalHandlers
> <http://root.cern.ch/root/html/TSystem.html#TSystem:GetListOfSignalHandlers>()
> seems a little bit cumbersome. Any hints? cheers,
> filimon
>
> On 01/26/2011 03:30 PM, Philippe Canal wrote:
>> Hi,
>>
>> See TInterruptHandler in core/rint/src/TRint.cxx and core/rint/src/TRint.h
>> and use gSystem->SetSignalHandler.
>>
>> Cheers,
>> Philippe
>>
>> On 1/26/11 8:15 AM, Filimon Roukoutakis wrote:
>>> Hi, I would like to catch ctrl-C while my long loop is running under a
>>> ROOT session and then terminate gracefully back to the ROOT prompt (at
>>> the moment, depending on the stage within the loop (deep calls in other
>>> third-party libraries) I get the prompt, unhandled exceptions or crash).
>>> Schematically what we want to achieve is
>>> shell prompt> root
>>> [0] gSystem->Load("mylib.so")
>>> [1] myProcess->Run(<100000 times for ~3 hours>)
>>> .....
>>> <at some point pressing ctrl-C and returning gracefully to>
>>> [2]
>>> Is there any tutorial on this? I see the classes TSignalHandler but a
>>> piece of working code would help. Quickly greping in $ROOTSYS/tutorials
>>> did not return something. I would like if possible to avoid using
>>> signal/slots ie the signal handler should preferably call directly a
>>> function and not raise a ROOT/Qt type signal (but this scenario is
>>> acceptable too).
>>> Thanks,
>>> filimon
>

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers_at_cern.ch              Phone: +41 22 7679248
WWW:    http://fons.rademakers.org           Fax:   +41 22 7669640
Received on Wed Jan 26 2011 - 17:16:15 CET

This archive was generated by hypermail 2.2.0 : Wed Jan 26 2011 - 17:50:01 CET