Thinking hard about this clock issue made me realize there is a race here.
If some event (data, keystroke or signal) is delivered very close to the select() timeout, select() could catch it and return a positive value, even though the timeout is just expiring. This means that select() returning zero is not a reliable way of knowing whether the clock display needs to be updated.
Instead of looking at the return value of select(), update the clock when the seconds have changed.
Thinking hard about this clock issue made me realize there is a race here.
If some event (data, keystroke or signal) is delivered very close to the select() timeout, select() could catch it and return a positive value, even though the timeout is just expiring. This means that select() returning zero is not a reliable way of knowing whether the clock display needs to be updated.
Instead of looking at the return value of select(), update the clock when the seconds have changed.