hi, I try to intercept real-time signals (SIGMIN + 1, SIGMIN +2 ...) it works when I send a signal (kill -35 PID) it works well only if i send one signal, when i send another signal or same signal second time (kill -35 PID) the pogram does not intercept the signal I feel that run () stops the service after having received the first signal Thank you for your help, Here are the code: #define SIG1 (SIGRTMIN + 1) #define SIG1 (SIGRTMIN + 2) ... class Agent { ... signal_handler(const boost::system::error_code& error, int signal_number) {...} ... } ... boost::asio::signal_set signals(io_serv); signals.add(SIG1) signals.add(SIG2) ... signals.async_wait( boost::bind(&Agent::signal_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::signal_number)); io_serv.run(); for (;;) { std::this_thread::yield(); } (I use Linux and g++) -- Merci d'avance Halim DJERROUD
On 12/08/2014 04:14, Halim DJERROUD wrote:
I try to intercept real-time signals (SIGMIN + 1, SIGMIN +2 ...) it works when I send a signal (kill -35 PID) it works well only if i send one signal, when i send another signal or same signal second time (kill -35 PID) the pogram does not intercept the signal [...] #define SIG1 (SIGRTMIN + 1) #define SIG1 (SIGRTMIN + 2)
I'm assuming that's a typo.
signals.async_wait( boost::bind(&Agent::signal_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::signal_number)); io_serv.run(); for (;;) { std::this_thread::yield(); }
async_wait is an operation that will wait for a single signal and then call the hander. Once this has been done, the operation is complete. If you want to be able to catch multiple signals, you need to call async_wait again within your signal handler to start a new operation. You can either call async_wait at the top of your signal handler to potentially process signals in parallel (if you have more than one io_service thread), or you can call it at the bottom to ensure that signals cannot be processed concurrently (albeit possibly not on the same thread, again). Also bear in mind that your threads implementation might be using some of the RT signals already, so make sure you don't collide with them.
Thank you very much John,
You solved my problem
I undestant , run() indeed stops the service after having received the
first signal.
Within handler(), we need to call another async_wait(), to keep the loop
running - as long as there's at least one async event to wait for, the loop
is running. When all events have been completed, the loop ends.
Thanks
2014-08-14 1:11 GMT+02:00 Gavin Lambert
On 12/08/2014 04:14, Halim DJERROUD wrote:
I try to intercept real-time signals (SIGMIN + 1, SIGMIN +2 ...) it works when I send a signal (kill -35 PID) it works well only if i send one signal, when i send another signal or same signal second time (kill -35 PID) the pogram does not intercept the signal
[...]
#define SIG1 (SIGRTMIN + 1)
#define SIG1 (SIGRTMIN + 2)
I'm assuming that's a typo.
signals.async_wait( boost::bind(&Agent::signal_handler, this,
boost::asio::placeholders::error, boost::asio::placeholders::signal_number)); io_serv.run(); for (;;) { std::this_thread::yield(); }
async_wait is an operation that will wait for a single signal and then call the hander. Once this has been done, the operation is complete.
If you want to be able to catch multiple signals, you need to call async_wait again within your signal handler to start a new operation.
You can either call async_wait at the top of your signal handler to potentially process signals in parallel (if you have more than one io_service thread), or you can call it at the bottom to ensure that signals cannot be processed concurrently (albeit possibly not on the same thread, again).
Also bear in mind that your threads implementation might be using some of the RT signals already, so make sure you don't collide with them.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Cordialement Halim DJERROUD
participants (2)
-
Gavin Lambert
-
Halim DJERROUD