aiso signal handling, daemon shutdown
Hello, I try to create a working example for a daemon with http://www.boost.org/doc/libs/1_50_0/doc/html/boost_asio/overview/signals.ht... I have created a program like: static bool run = true; void handler( const boost::system::error_code& error, int signal_number) { if (!error) { run = false; std::cout << "signal" << std::endl; } } and the main with int main(..) { boost::asio::io_service io_service; boost::asio::signal_set signals(io_service, SIGINT, SIGTERM); signals.async_wait(handler); while (run) { boost::this_thread::yield(); } } The program runs, but if I do "kill pid" the program does not stop or shows the message. I would like to create a small daemon which runs some threads and can stop with the normal stop signal and can reload the configuration on reload. Can anyone help me to create a working example first !? Thanks a lot Phil
Hello,
I try to create a working example for a daemon with
http://www.boost.org/doc/libs/1_50_0/doc/html/boost_asio/overview/signals.ht ml
I have created a program like:
static bool run = true;
void handler( const boost::system::error_code& error, int signal_number) { if (!error) { run = false; std::cout << "signal" << std::endl; } }
and the main with
int main(..) { boost::asio::io_service io_service; boost::asio::signal_set signals(io_service, SIGINT, SIGTERM); signals.async_wait(handler);
while (run) { boost::this_thread::yield(); } }
The program runs, but if I do "kill pid" the program does not stop or
shows the message.
I would like to create a small daemon which runs some threads and can stop with the normal stop signal and can reload the configuration on reload.
Can anyone help me to create a working example first !? Thanks a lot
Your asynchronous handlers are not running because you forgot to call " io_service.run()." ~Dan
Am 13.07.2012 um 22:05 schrieb Casimiro, Daniel C CIV NUWC NWPT:
Hello,
I try to create a working example for a daemon with
http://www.boost.org/doc/libs/1_50_0/doc/html/boost_asio/overview/signals.ht ml
I have created a program like:
static bool run = true;
void handler( const boost::system::error_code& error, int signal_number) { if (!error) { run = false; std::cout << "signal" << std::endl; } }
and the main with
int main(..) { boost::asio::io_service io_service; boost::asio::signal_set signals(io_service, SIGINT, SIGTERM); signals.async_wait(handler);
while (run) { boost::this_thread::yield(); } }
The program runs, but if I do "kill pid" the program does not stop or
shows the message.
I would like to create a small daemon which runs some threads and can stop with the normal stop signal and can reload the configuration on reload.
Can anyone help me to create a working example first !? Thanks a lot
Your asynchronous handlers are not running because you forgot to call " io_service.run()."
Damn, I have forgot the run command. I have added before the loop and it works :-P Thanks Phil
participants (2)
-
Casimiro, Daniel C CIV NUWC NWPT
-
Kraus Philipp