linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Correct handling of signal
@ 2015-08-20  8:14 Florian Lindner
  0 siblings, 0 replies; only message in thread
From: Florian Lindner @ 2015-08-20  8:14 UTC (permalink / raw)
  To: linux-c-programming

Hello,

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 
std::abort?

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

Best Regards,
Florian



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-08-20  8:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-20  8:14 Correct handling of signal Florian Lindner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).