Domanda

I write a library, register signal handler in function that application always called. I register following signals:

  • SIGQUIT
  • SIGINT
  • SIGKILL
  • SIGCHLD
  • SIGHUP
  • SIGSTOP
  • SIGTERM

All signal handlers point to same function just like that:

signal(SIGQUIT,signal_handler);
signal(SIGINT,signal_handler);
signal(SIGKILL,signal_handler);
....

When I run the application, and exited NORMALLY, there aren't any signals raised at all. But if I break it with <ctrl-c>, SIGINT will raised and my signal handler is triggered,too. Why aren't any signals raised when the application exited normally?

È stato utile?

Soluzione

Because that's how it works. Signals are only raised when something abnormal happens.

If you want to run something when the program exits normally, try using atexit() or on_exit().

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top