hektor
hektor

Reputation: 1025

Is it possible to configure more than 3 timers using setitimer?

How can I configure more than 3 timers using setitimer? The linux man page says "The system provides each process with three interval timers, each decrementing in a distinct time domain. When any timer expires, a signal is sent to the process, and the timer (potentially) restarts" .

Upvotes: 2

Views: 1702

Answers (3)

Travis J
Travis J

Reputation: 82287

Use a mod check on a single timer to abstract it out to many timers. This is how google handles their multiple timers in javascript and I would assume it could work here too. The reasoning is that it is orders of magnitudes faster than running multiple timers consecutively.

In other words, if you have a timer which runs ever 5ms, and you had a count of how many times it had run, then you could mod that count and every 10 of those would be a 50ms timer as well.

Upvotes: 0

torek
torek

Reputation: 488193

Linux offers timer_create (since 2.6) to make new interval timers: http://www.kernel.org/doc/man-pages/online/pages/man2/timer_create.2.html.

If you find yourself using a system that has only the basic timers, you can always create your own in a user-written library.

There is also timerfd_create (also Linux-specific).

Upvotes: 2

Andy Ross
Andy Ross

Reputation: 12043

You are limited to three with the itimer mechanism. See timerfd_create() for a more modern replacement (albeit linux-only) which doesn't have this limitation. It also works on a file descriptor instead of signals, so can be more easily integrated with event loops implemented with select/poll.

Upvotes: 2

Related Questions