• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1544
  • Last Modified:

Linux variant for Windows Sleep command

Can someone please tell me how to implement a sleep command for Linux in the same was as the Windows variant.

The Windows version tells the current process to go to sleep and stops it for a number of milliseconds, but allows other functions/threads in the application to work in the background. How do I do this in Linux????

I want to let other threads do their bit, by waiting for one second.

I saw the sleep and usleep command in Linux but does this do what I need???

I am coding in QT3 / C++ on SuSE.

regards,

Gordon?
0
jeffreyg
Asked:
jeffreyg
1 Solution
 
Karl Heinz KremerCommented:
sleep() will definitely give up the CPU so that other threads or processes can run. usleep() will give up the CPU if you sleep for more than about 50 milliseconds. For shorter usleep amounts, it would be too timeconsuming to do a task switch, so the usleep command will do a busy wait.

if you want to wait for one second, do a sleep(1), this will give your other processes time to run.
0
 
jeffreygAuthor Commented:
Thats all I needed to know, thanks khkremer!!!! Pts are yours.

regards,

Gordon.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now