The standard C library contains <signal.h>(for example, see here ), with which you can register a signal handler for SIGINT (Ctrl-C). This should do the trick, assuming your platform supports signals.
, SIGTERM, (1) ed.
#include <signal.h> // or <csignal> in C++
void ctrlchandler(int) { WE_MUST_STOP = 1; }
void killhandler(int) { WE_MUST_STOP = 2; }
int WE_MUST_STOP = 0;
int main() {
signal(SIGINT, ctrlchandler);
signal(SIGTERM, killhandler);
while(pump_loop() && 0 == WE_MUST_STOP) { }
}
, , boost.asio m_io_service.run(). ( , m_io_service) post io .