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

timer_create() : -1 EAGAIN (Resource temporarily unavailable)

本文关键字:资源 create timer EAGAIN      更新时间:2023-10-16

我在运行ARM的嵌入式Linux下创建计时器遇到了麻烦。我使用自制的c++库来管理计时器。我没有自己编写代码,尽管我可以访问源代码,但我对实现并不了解……它工作了一段时间,然后我得到了错误"EAGAIN"。

使用strace我注意到,当它不工作的定时器ID是安静的高!

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

看到相当低的定时器ID时,它的工作:

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

我以为定时器的数量是无限的!真的不是吗?我们应该在完成任务后销毁计时器吗?我还使用了"timer_stats"内核实用程序,但这对我没有多大帮助……内核内是否有其他计时器调试工具或其他工具?

谢谢你的帮助!

您猜对了,您确实有定时器的最大数目:

   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)).

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.

虽然您可以提高挂起信号的setrlimit(2)限制(bash(1)中的ulimit -i),但要注意,这会分配真正的内核内存——这是一种极其有限的资源。

我建议修改您的应用程序以删除或重新使用旧的计时器。