Periodic timer using SIGUSR2 causes bypass of getchar()


SIGEV_SIGNAL_INIT (&health_event, SIGUSR2);
signal( SIGUSR2, Health_MonitorExpired );

if (timer_create (CLOCK_REALTIME, &health_event, &health_tid) == -1)


I’ve used the above technique to create a timer running with a 2sec period.
After starting the timer I run on into a getchar().
Each time the timer expires it executes “Health_MonitorExpired” as expected
but also drops through the getchar() as if the keyboard has been pressed ?
Any ideas ?

Neil Richardson wrote:


SIGEV_SIGNAL_INIT (&health_event, SIGUSR2);
signal( SIGUSR2, Health_MonitorExpired );

if (timer_create (CLOCK_REALTIME, &health_event, &health_tid) == -1)


I’ve used the above technique to create a timer running with a 2sec period.
After starting the timer I run on into a getchar().
Each time the timer expires it executes “Health_MonitorExpired” as expected
but also drops through the getchar() as if the keyboard has been pressed ?
Any ideas ?

Nearly all I/O functions are not signal safe. In fact, the getchar is
failing (-1 iirc), the errno value is EINTR I think. Basically, any time
you use signals you must test all io calls for the EINTR response. This
is such a pain I try not to use signals!

Phil Olynyk
OBT Software Corp.

Or handle your signals in a seperate thread.

But, of course after EVERY IO you should check your return codes.


Bill Caroselli – 1(626) 824-7983
Q-TPS Consulting
QTPS@EarthLink.net


“Phil Olynyk” <pholynyk@rogers.com> wrote in message
news:3C990411.E0D1F501@rogers.com

Neil Richardson wrote:


SIGEV_SIGNAL_INIT (&health_event, SIGUSR2);
signal( SIGUSR2, Health_MonitorExpired );

if (timer_create (CLOCK_REALTIME, &health_event, &health_tid) == -1)


I’ve used the above technique to create a timer running with a 2sec
period.
After starting the timer I run on into a getchar().
Each time the timer expires it executes “Health_MonitorExpired” as
expected
but also drops through the getchar() as if the keyboard has been pressed
?
Any ideas ?

Nearly all I/O functions are not signal safe. In fact, the getchar is
failing (-1 iirc), the errno value is EINTR I think. Basically, any time
you use signals you must test all io calls for the EINTR response. This
is such a pain I try not to use signals!

Phil Olynyk
OBT Software Corp.

Thanks for responding guys …

Using ‘pulses’ seems to be less of a headache !

Regards
Neil R.

Yes this is also what pulses are for!
cheers
Alain.

Neil Richardson wrote:

Thanks for responding guys …

Using ‘pulses’ seems to be less of a headache !

Regards
Neil R.