简体   繁体   English

除了 POSIX 计时器,Linux 中的其他计时器 API 是什么?

[英]What are the other timer APIs in Linux apart from POSIX timers?

I want to design a timer in Linux, but due to some system constraints and design requirements i cannot use the POSIX timer APIs.我想在 Linux 中设计一个计时器,但由于一些系统限制和设计要求,我无法使用 POSIX 计时器 API。

Can somebody kindly let me know, what are the other timer design mechanisms available in Linux apart from the POSIX timers?有人可以告诉我,除了 POSIX 计时器之外,Linux 中还有哪些其他计时器设计机制? (timer_create, timer_settime etc to avoid) (timer_create、timer_settime 等要避免)

Thanks in advance.提前致谢。

EDIT: PS: Any mechanism you provide, requesting you to kindly give me some useful links or example links编辑:PS:您提供的任何机制,请您给我一些有用的链接或示例链接

NOTE: We can't use any third party library (Like ACE library) as our code is a proprietory code.注意:我们不能使用任何第三方库(如 ACE 库),因为我们的代码是专有代码。

Check out my answer .看看我的回答 One of the timers I find useful is timerfd_create() API provided in Linux system call.我发现有用的计时器之一是在 Linux 系统调用中提供的timerfd_create() API。 This blends well when your application is structured on an event loop.当您的应用程序基于事件循环构建时,这很好地融合了。

If you are looking for 3rd party, there is an ACE library that can be downloaded for free.如果您正在寻找第 3 方,可以免费下载 ACE 库。 They have timers, queues, threads etc他们有计时器、队列、线程等

The simplest and most portable way is probably just to use pthread_create and clock_nanosleep to implement your own timer.最简单和最便携的方法可能就是使用pthread_createclock_nanosleep来实现自己的计时器。 It shouldn't take more than about 50 lines of code for something simple, and maybe 100-150 for a fully general API with overrun counts, etc.简单的事情不应该超过大约 50 行代码,对于具有溢出计数等的完全通用的 API 可能需要 100-150 行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM