开发者

how to make an application resilient to clock_settime

An application (running on linux 2.6.31) is paced using usleep calls. However, it looks like it is not resilient to a date change (either using date from a shell or using clock_settime from another process). What is the right thing to do to avoid the application to be locked ?

edit1

Say the application wants to do something开发者_开发知识库 every 100ms. When the job is done, it calls gettimeofday, and deduce the remaining ms to sleep until the next 100ms slice, then it calls usleep.


If you have to be sure about time interval, not regarding the current date/time, you have to use this call :

struct timespec tim;
uint64_t microsec;

clock_gettime( CLOCK_MONOTONIC, &tim );
microsec= 1000000ULL * tim.tv_sec + tim.tv_nsec / 1000;

It is your system uptime, real full "hardware" time ( cannot be modified ).

About your periodic routine, you can set the periodic handler with alarm() and setitimer().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜