简体   繁体   English

timer_create(): - 1 EAGAIN(资源暂时不可用)

[英]timer_create() : -1 EAGAIN (Resource temporarily unavailable)

I'm having trouble to create timer under my embedded Linux running ARM. 我在运行ARM的嵌入式Linux下创建计时器时遇到了麻烦。 I'm using a home made C++ library to manage timer. 我正在使用自制的C ++库来管理计时器。 I didn't code it myself, I don't know deeply the implementation despite I have access to the source code... It works for a while and then I got the error "EAGAIN". 我自己没有编写代码,尽管我已经访问了源代码,但我并不深入了解实现...它工作了一段时间然后我得到了错误“EAGAIN”。

Using strace I noticed that when it doesn't work the timer ID is quiet high! 使用strace我注意到当它不起作用时,计时器ID安静高!

timer_create(CLOCK_MONOTONIC, {0, SIGRT_3, SIGEV_SIGNAL, {...}}, 0xbed50af4) = -1 EAGAIN (Resource temporarily unavailable)

See the pretty low timer ID when it's working: 在工作时看到相当低的计时器ID:

timer_create(CLOCK_MONOTONIC, {0x3, SIGRT_3, SIGEV_SIGNAL, {...}}, {0x3d}) = 0

I thought that the number of timers was unlimited! 我以为定时器的数量是无限的! Actually not? 其实并不是? Should we destroy the timer once we are done with it? 一旦我们完成计时器,我们应该销毁它吗? I also used the "timer_stats" kernel utility but this didn't help me much ... Are there other debug utility for the timers inside the kernel or any other tool? 我还使用了“timer_stats”内核实用程序,但这对我没有多大帮助......内核中的定时器还是其他任何工具都有其他调试工具吗?

Thanks for your help! 谢谢你的帮助!

You've guessed correctly, you do have a maximum number of timers: 你猜错了,你确实有最多的计时器:

   The kernel preallocates a "queued real-time signal" for each
   timer created using timer_create().  Consequently, the number
   of timers is limited by the RLIMIT_SIGPENDING resource limit
   (see setrlimit(2)).

The timer_create(3posix) manpage is a bit more blunt about it: timer_create(3posix)联机帮助页对此更为直率:

   The timer_create() function shall fail if:

   EAGAIN The system lacks sufficient signal queuing resources
          to honor the request.

   EAGAIN The calling process has already created all of the
          timers it is allowed by this implementation.

While you could raise the setrlimit(2) limit on pending signals ( ulimit -i in bash(1) ), be aware that this allocates real kernel memory -- which is an extremely limited resource. 虽然你可以提高挂起信号的setrlimit(2)限制( bash(1) ulimit -i ),但要注意这会分配真正的内核内存 - 这是一个非常有限的资源。

I suggest modifying your application to delete or re-use old timers. 我建议修改您的应用程序以删除或重新使用旧计时器。

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

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