Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 08-03-2009, 11:10 PM   #1
Registered: May 2007
Location: New Zealand
Distribution: Ubuntu
Posts: 88

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


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.

Old 08-04-2009, 05:12 AM   #2
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,293

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335

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, 07:25 PM   #3
Senior Member
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 4,709

Rep: Reputation: 744Reputation: 744Reputation: 744Reputation: 744Reputation: 744Reputation: 744Reputation: 744
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.

Old 08-05-2009, 12:32 AM   #4
Registered: May 2007
Location: New Zealand
Distribution: Ubuntu
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:
for (i=0;i<100000000;i++);
that it would use cpu resources??
Old 08-05-2009, 01:22 AM   #5
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397

    <your code>

    /* some sleep, pick a number */


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 02:30 AM
Schedule a script to run philipo Slackware 3 06-22-2007 06:10 PM
how to run a schedule in every 2 mins!! rahulrawat Red Hat 7 12-24-2005 07:58 PM
mailing myself at regular intervals... piyushiitk Programming 4 08-21-2005 11:26 AM
Schedule a Script to Run nutthick Linux - Newbie 8 02-02-2005 01:37 PM > Forums > Linux Forums > Linux - Software

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

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