The manual page getitimer(2) claims that
both tv_sec and tv_usec significant in determining the duration of a timer
It doesn't go on to say why that is. In many examples that I have come across tv_sec is simply set to 0, while tv_usec is given some reasonable value, or vis versa. Are these timers counting down simultaneously, or is the total countdown time tv_sec + tv_usec? Should I use both? Neither?
The man page documents the timeval
structure:
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* microseconds */
};
If you want to wait a whole number of seconds, you'd just set tv_sec
. If you want to wait a portion of a second, you'd set tv_usec
. If you want to wait 4.5 seconds, you'd set both of them to appropriate values (4 and 500000, respectively)
Yes, the total time is the sum of both. tv_sec is the seconds. And tv_usec is microseconds beyond that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With