LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-07-2004, 10:13 AM   #1
samble
LQ Newbie
 
Registered: Nov 2003
Posts: 15

Rep: Reputation: 0
Help with Linux timers


Here is what I want to do. I want to create a timer and set it to expire after certain time. When It expires I want to send some data to the signal handler. The data is multiple bytes (may be as much as 24 bytes). Here is how you can help me out:

1. Point me to some tutorial which will explain the intricacies of timer functionality in Linux.
2. Provide pointers to help me solve the problem.

Thanks for all helpful suggestions.

Srini
 
Old 02-07-2004, 01:11 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,627
Blog Entries: 10

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
Is this a programming question or are you
looking for the "at" command?


Cheers,
Tink
 
Old 02-07-2004, 01:28 PM   #3
samble
LQ Newbie
 
Registered: Nov 2003
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks for taking time to read my request.

This is more of a programming question.

Kind regards

Srini
 
Old 02-07-2004, 01:39 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,627
Blog Entries: 10

Rep: Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776Reputation: 776
man setitimer
man getitimer

Or, if you're looking for a portable C++
solution, have a look at Qt's qtimer class.

The latter comes with programming examples,
too :)


Cheers,
Tink

P.S.: You should ask a mod to move the
thread to the programming-forum. It clearly
doesn't belong here.
 
Old 02-07-2004, 03:13 PM   #5
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,068
Blog Entries: 4

Rep: Reputation: 385Reputation: 385Reputation: 385Reputation: 385
Moved to Programming
 
Old 02-07-2004, 03:52 PM   #6
jtshaw
Moderator
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 63
Ya, look at the man page for setitimer. It'll allow you to set the timer, and it tells you what signal is fired when it runs out. You can then define what happens when you get that signal.
 
Old 02-07-2004, 04:41 PM   #7
samble
LQ Newbie
 
Registered: Nov 2003
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks for all the good replies. "setitimer" may be too restrictive because from what I understand you can have no more than three interval timers per process. In my case I have several devices on which I will have to react based on the timers. My next questions are:

1. Is there a limitation to the number of timers per process/task I can create via timer_create() function?
2. If I can create a number of timers, I am still at a loss as to how I can associate the timer expiry to a particular device.

Thanks for all helpful suggestions.

Srini
 
Old 02-07-2004, 05:30 PM   #8
jtshaw
Moderator
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 63
Well the way a timer like that works is it typically triggers a software interupt which causes a signal to be sent to the processor. You have to create a function that is suppose to run based on that signal. Are you using this for doing operations on hardware? Perhaps you should write a kernel module.
 
Old 02-07-2004, 10:54 PM   #9
schmack
LQ Newbie
 
Registered: Feb 2004
Posts: 12

Rep: Reputation: 0
I assume this is a simple user-space program, not a kernel module, so let's keep it simple here...

1) Have a linked list of "timer" objects that contain references back to the particular device.
2) Keep the list sorted by the expiration time, most recent first.
3) Use setitimer to send a signal when the earliest expiration time will occur.
4) In the signal handler, walk through the timer list, calling an "expire" method against the object if the timeout has occurred. Stop when you hit a timer that hasn't expired.
5) Calculate the next interval and set your itimer.

I haven't used the qtimer classes, but I'll bet they are just what you are looking for.

If you need it, I can whip up a simple set of timer classes for an example.

-Craig
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
about timers eshwar_ind Programming 1 12-27-2004 09:23 AM
C - Linux - Timers - How? drigz Programming 6 08-30-2004 02:36 PM
Pls Help, Singals and Timers problem in RedHat Linux 7.3 kumarnine Programming 2 08-26-2004 09:16 AM
timers is user space in linux gooner Programming 0 06-07-2004 03:52 AM
Any old timers out there remember 486's? shmoo28 Linux - Software 4 11-07-2001 08:19 AM


All times are GMT -5. The time now is 05:02 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration