Onega

a lot of VC++ posts, a few C# posts, and some miscellaneous stuff

Saturday, April 26, 2014

Ctrl+C handling

Handle SIGINT via ACE
extern "C" void handler (int)
{ACE_DEBUG ((LM_DEBUG, "%s\n", __FUNCTION__));
// shutdown application
}
ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT);

Handle SIGINT via boost.asio
void handler(
    const boost::system::error_code& error,
    int signal_number)
{
  if (!error)
  {
    // A signal occurred.
  }
}
boost::asio::signal_set signals(io_service, SIGINT, SIGTERM);
signals.async_wait(handler);

QT uses QSocketNotifier and sigaction together, see Calling Qt Functions From Unix Signal Handlers

Windows Console application, see CTRL_C_EVENT and SetConsoleCtrlHandler.

0 Comments:

Post a Comment

<< Home