Posts Usage of timers - what you need to know about them?
Post
Cancel

Usage of timers - what you need to know about them?

I had written an earlier article on Timers in Linux. In this article I share with you a slideshow on what is possible with timers and what is not achievable, so that you may clearly understand how timers can be used during system programming under a linux host or linux target based environment.


The following points are worth noting about timers

  • The time is stored relative to a certain date in history (Jan 1, 1970), so when you read the time, its always a number relative to this date. This is called EPOCH time or the UNIX EPOCH time.
  • Each process is allocated one timer, this is called per process timer.
  • iTimers which are of three types: REAL, VIRTUAL and PROF
  • how to initialize countdown timers and use them
  • iTimerVal and timeval structures
  • it_interval, it_value, tv_sec, tv_usec variables and their possible values
  • using the signal handler function to handle timer expiry signals
  • how to set signal handlers while using timers
  • types of signals that can be sent to process or across processes (SIGALRM)

So its now easy for you to write a small timer program in linux and compile it using the following :

gcc timer_example.c p-o timer_example

run it using

./timer_example

and check your logs to see if the timers did expire properly! As you would be aware the timer is a per process timer which means within a process, if you require timeouts at different intervals it has to be an enhancement over a single timer. So you could expire a single timer every say 1 second or 10 milliseconds or whatever value you want (at a granular level) and provide a specific interrupt to the process or other processes every “N” seconds or milliseconds where “N” is a multiple of the it_value variable within the timeval structure.

Try it out yourself and be rest assured it ll work like a charm.

Technorati Tags: Software Development, Timeval, ITimer, SetITimer, GetITimer, Linux, Unix, Timers, Signals, Signal handler, Usage, Sigalrm, Real timer, Virtual timer, Prof timer, Man, Bangalore, Bengaluru, Technology, Blog

This post is licensed under CC BY 4.0

Trending Tags

Contents

Trending Tags