LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 08-03-2009, 10:10 PM   #1
AustinMarton
Member
 
Registered: May 2007
Location: New Zealand
Distribution: Fedora at home, Ubuntu 10.04 at work
Posts: 88

Rep: Reputation: 16
How do I schedule a userspace application to run at regular intervals


Hello,

I am writing a userspace application to send out a packet on uClinux on Nios2, it needs to be run at regular intervals (from about 1 to 64 times a second - to be set by user) but the timing does not need to be accurate (otherwise I would use a hardware counter to generate interrupts).

Can I some how create a software interrupt/timer overflow or something along those lines to start my application every second? Or some way I can use a shell script to start it?

I have read up about Kernel Timers but I would prefer to not have to write another driver.

I could just wrap the program in a while loop with a delay but this seems very crude. This is an embedded system so there is a need to conserve resources.

Thanks,
Austin.
 
Old 08-04-2009, 04:12 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,149

Rep: Reputation: 236Reputation: 236Reputation: 236
Hi

No matter how you do it, starting a program every second will take quite a lot of resources. So I think it's better to have the program start once and then just sleep/usleep/nanosleep in the while loop. Why do you think it's "very crude"?
 
Old 08-04-2009, 06:25 PM   #3
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,171

Rep: Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506Reputation: 506
It is not crude to delay a process. If you sleep a process it is simply not run by the kernel until the moment the sleep timer expires, and it doesn't take up any resources.

For repeating jobs with a period less than 2 minutes, it is recommended to start the process once and have a sleep to schedule when parts of the program must be run.

jlinkels
 
Old 08-04-2009, 11:32 PM   #4
AustinMarton
Member
 
Registered: May 2007
Location: New Zealand
Distribution: Fedora at home, Ubuntu 10.04 at work
Posts: 88

Original Poster
Rep: Reputation: 16
Great! Thanks! That makes sense, I will use a mdelay/udelay combo.

The reason for my crude comment was I thought that if I had a loop like:
Code:
for (i=0;i<100000000;i++);
that it would use cpu resources??
 
Old 08-05-2009, 12:22 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,301

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Use

Code:
while(1)
{
    <your code>

    /* some sleep, pick a number */
    usleep(5); 
}
 
  


Reply

Tags
application, interrupt, kernel, software, space, timer, trigger, user


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to schedule to run a script? ArthurHuang Programming 2 05-22-2009 01:30 AM
Schedule a script to run philipo Slackware 3 06-22-2007 05:10 PM
how to run a schedule in every 2 mins!! rahulrawat Red Hat 7 12-24-2005 06:58 PM
mailing myself at regular intervals... piyushiitk Programming 4 08-21-2005 10:26 AM
Schedule a Script to Run nutthick Linux - Newbie 8 02-02-2005 12:37 PM


All times are GMT -5. The time now is 06:24 PM.

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 Google+: linuxquestions
Open Source Consulting | Domain Registration