C语言中的计时器(如Java) [英] Timer in C (like in Java)
问题描述
您好,我需要一个C语言中的设施,就像一组函数一样,来管理一个
计时器:我应该可以在一段时间内初始化它
(比如x毫秒),启动它,每x毫秒它应该执行某个
函数。简而言之,我需要类似java.util.Timer
类,但对于C(当然不是类)。
你知道任何实现吗?这样的事情(如果可能的话
实时)?
非常感谢
< blockquote> Alexander Mahone< sa ****************** @ gmail.comwrites:
你好,我需要C中的一个工具,就像一组函数一样,用来管理一个
计时器:我应该能够在一段时间内初始化它
(比如x毫秒) ,启动它,每x毫秒它应该执行某个
函数。简而言之,我需要类似java.util.Timer
类,但对于C(当然不是类)。
你知道任何实现吗?这样的事情(如果可能的话,实时是b $ b)?
不在标准C.尝试新闻组处理您的操作
系统。
-
Keith Thompson(The_Other_Keith)< ks *** @ mib.org>
诺基亚
我们必须做点什么。这是事情。因此,我们必须这样做。
- Antony Jay和Jonathan Lynn,是部长
Alexander Mahone写道:
您好,我需要一个C语言中的工具,就像一组函数一样,来管理一个
计时器:我应该能够初始化它有一段时间
(比如x毫秒),启动它,每x毫秒它应该执行某个
函数。简而言之,我需要类似java.util.Timer
类,但对于C(当然不是类)。
你知道任何实现吗?这样的事情(如果可能的话
实时)?
非常感谢
标准C有没有你想做的设施。但POSIX
指定ualarm()和setitimer()用于在
指定的时间段后中断进程。然后信号处理程序可以调用您的函数。
< http://www.mkssoftware.com/docs/man3/ualarm.3.asp>
< http://www.mkssoftware.com/docs/man3/setitimer.3.asp>
在文章< fu *** ******@registered.motzarella.org> ;,
santosh< sa ********* @ gmail.comwrote:
>标准C没有您想要做的设施。但是,POSIX
指定ualarm()和setitimer()用于在指定的时间段后中断进程。然后信号处理程序可以调用您的函数。
两个函数都不是POSIX.1-1990的一部分。
ualarm()从第4期开始被添加到POSIX ,版本2,并从
X / OPEN UNIX扩展转移到第5期的BASE(我认为是2002年)。
截至第6期(2004年), ualarm()标记为过时。
http:/ /www.opengroup.org/onlinepubs/...ns/ualarm.html
setitimer()也被添加并移动到与ualarm()相同的问题,
但是setitimer()没有标记为过时。
http://www.opengroup.org/onlinepubs/...getitimer.html
有关-recommended-的信息POSIX计时器功能是
及其各种权衡,unix编程新闻组应该咨询
。
-
沃尔特示例类。 - Paul Tagliabue
Hello, I need a facility in C, like a set of functions, to manage a
timer: I should be able to initialize it with a certain period of time
(like x msec), start it, and every x msec it should execute a certain
function. In a few words, I need something like the java.util.Timer
class, but for C (of course not a class).
Do you know of any implementation of something like that (if possible
real-time)?
Thanks a lot
Alexander Mahone <sa******************@gmail.comwrites:Hello, I need a facility in C, like a set of functions, to manage a
timer: I should be able to initialize it with a certain period of time
(like x msec), start it, and every x msec it should execute a certain
function. In a few words, I need something like the java.util.Timer
class, but for C (of course not a class).
Do you know of any implementation of something like that (if possible
real-time)?Not in standard C. Try a newsgroup that deals with your operating
system.
--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Alexander Mahone wrote:
Hello, I need a facility in C, like a set of functions, to manage a
timer: I should be able to initialize it with a certain period of time
(like x msec), start it, and every x msec it should execute a certain
function. In a few words, I need something like the java.util.Timer
class, but for C (of course not a class).
Do you know of any implementation of something like that (if possible
real-time)?
Thanks a lotStandard C has no facilities for what you want to do. However POSIX
specifies ualarm() and setitimer() for interrupting a process after a
specified period. A signal handler can then call your function.
<http://www.mkssoftware.com/docs/man3/ualarm.3.asp>
<http://www.mkssoftware.com/docs/man3/setitimer.3.asp>
In article <fu*********@registered.motzarella.org>,
santosh <sa*********@gmail.comwrote:
>Standard C has no facilities for what you want to do. However POSIX
specifies ualarm() and setitimer() for interrupting a process after a
specified period. A signal handler can then call your function.Neither function was part of POSIX.1-1990.
ualarm() was added to POSIX as of Issue 4, Version 2, and moved from
X/OPEN UNIX extension to BASE of of issue 5 (which I think was 2002.)
As of issue 6 (2004), ualarm() is marked obsolescent.
http://www.opengroup.org/onlinepubs/...ns/ualarm.html
setitimer() was also added and moved at the same issues as for ualarm(),
but setitimer() is not marked obsolescent.
http://www.opengroup.org/onlinepubs/...getitimer.html
For information about what the -recommended- POSIX timer functions are
and their various trade-offs, a unix programming newsgroup should
be consulted.
--
"Walter exemplified class." -- Paul Tagliabue
这篇关于C语言中的计时器(如Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!