?
Solved

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

Posted on 2003-03-11
4
Medium Priority
?
1,384 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
  • 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

621 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