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?

有帮助吗?

解决方案

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().

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top