linux定时器使用疑问

wgj1922 2012-09-12 08:45:19
Linux进程调度采用分时调度,用户态进程中起一个定时器,会发生定时器时间到时,进程没有得到调度么?在进程中可以使用低于最小时间片,比如低于5ms的定时器么?
...全文
77 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mymtom 2012-09-17
  • 打赏
  • 举报
回复
会发生的,无论是alarm, setitimer 还是 select. 都会受到系统定时精度的影响,就是说定时器时间到了以后,并不能保证进程马上被调度。

unsigned int alarm(unsigned int seconds);

The alarm() function causes the system to generate a SIGALRM signal for the process after the number of real-time seconds specified by seconds have elapsed. [B]Processor scheduling delays may prevent the process from handling the signal as soon as it is generated. [/B]


===========================
int getitimer(int which, struct itimerval *value);
int setitimer(int which, const struct itimerval *value,
struct itimerval *ovalue);


The getitimer() function stores the current value of the timer specified by which into the structure pointed to by value. The setitimer() function sets the timer specified by which to the value specified in the structure pointed to by value, and if ovalue is not a null pointer, stores the previous value of the timer in the structure pointed to by ovalue.

A timer value is defined by the itimerval structure. If it_value is non-zero, it indicates the time to the next timer expiration. If it_interval is non-zero, it specifies a value to be used in reloading it_value when the timer expires. Setting it_value to 0 disables a timer, regardless of the value of it_interval. Setting it_interval to 0 disables a timer after its next expiration (assuming it_value is non-zero).

Implementations may place limitations on the granularity of timer values. For each interval timer, if the requested timer value requires a finer granularity than the implementation supports, the actual timer value will be [B]rounded up to the next supported value[/B].

============================
int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *errorfds, struct timeval *timeout);


On successful completion, the object pointed to by the timeout argument may be modified.

Implementations may place limitations on the maximum timeout interval supported. On all implementations, the maximum timeout interval supported will be at least 31 days. If the timeout argument specifies a timeout interval greater than the implementation-dependent maximum value, the maximum value will be used as the actual timeout value. Implementations may also place limitations on the granularity of timeout intervals. If the requested timeout interval requires a finer granularity than the implementation supports, the [B]actual timeout interval will be rounded up to the next supported value[/B].
titer1 2012-09-13
  • 打赏
  • 举报
回复
高精度定时器没用过~不过感觉没有
qq120848369 2012-09-12
  • 打赏
  • 举报
回复
pselect,纳秒。

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧