Correct handling of signal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



I'm developing a scientific application that can be used standalone as well 
as a library.

We use connection files to exchange information about socket based 
connection. Upon an unclean exit these connection linger around, causing 
trouble on the next startup.

I implemented a signal handler to clean up on unclean exit:

  signal(SIGSEGV, precice::utils::terminationSignalHandler);
  signal(SIGABRT, precice::utils::terminationSignalHandler);
  signal(SIGTERM, precice::utils::terminationSignalHandler);
  signal(SIGINT,  precice::utils::terminationSignalHandler);

void terminationSignalHandler(int signal) { 
// use boost filesystem to clean up 

Since I'm a rather high level programmer I haven't had much contact with 
signals, some questions:

1) Can I assume the application to be in a condition to actually do 
something when these signals are called? I have doubts especially about 
SIGSEGV regarding corruption of internal data structures.

2) Can multiple signal handler be installed for one signal? Or do subsequent 
invocations of signal(...) overwrite the handler for the resp. signal? If we 
are used as a library and host application has installed own signal handler, 
how can we omit overwriting them?

3) If there are multiple handler for one signal, can we remove our handler 
from the chain and re-emit the signal? Or should be just use std::exit or 

4) Is this the right way to go for the problem described? Any comments 

Best Regards,

To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux