?
Solved

Linux timer (sleep, delay, pause, etc) function

Posted on 2003-03-11
4
Medium Priority
?
1,378 Views
Last Modified: 2012-05-04
I have a set of processes that I want done in an infinate loop.  Obviously if I put them into an actual loop, I will get 100% cpu usage (not acceptable).  A funtion that stoppes the loops for about a minute should (I am hoping) solve this problem.  The code must work in linux.

Example of what I need:

      do
      {
           reload();
           bandwith();
           fileload();
           filewrite();
     }
     while (FOREVER);

But, the above needs to be done every minute in a loop.  So I think something like do { timer(1minutes) } while (FOREVER) would solve this problem.
0
Comment
Question by:mrcool4444
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
akshayxx earned 500 total points
ID: 8117793
use sleep()
like this
sleep(N) sleeps for N seconds
if u want more precision .. use usleep() OR nanosleep
for more information look at the manual page on ur linux
man 2 sleep

do
     {
          reload();
          bandwith();
          fileload();
          filewrite();
sleep(60);
    }
    while (FOREVER);
0
 

Author Comment

by:mrcool4444
ID: 8117822
Hmm, man 2 sleep gives me: No entry for sleep in section 2 of the manual

I did manage to find that sleep() was located in unistd.h.

Everything works great now (except for the man page).

Thanks!
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 8118546
welcome .. btw u could have tried
man sleep
man 3 sleep
actually man sleep will give u the manual page for command line 'sleep'
usually library functions' man pages are in 2nd 3rd sections

any ways good to know it worked for u
0
 

Author Comment

by:mrcool4444
ID: 8121528
man 3 sleep did it :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question