usleep() to calculate elapsed time behaves weird

后端 未结 2 1260
南方客
南方客 2021-01-23 03:32

I am calculating time elapsed in milli seconds for each successive call to handler function using the code below. When i use usleep(1000) i.e. 1 ms time difference between each

2条回答
  •  无人共我
    2021-01-23 04:06

    Remember that the tv_usec field of the timeval structure never goes to (or over) one million, instead the number of seconds is increased.

    You have to use the tv_sec field as well in your calculation.

提交回复
热议问题