Solved

Sleep Function

Posted on 2003-11-07
4
38,026 Views
Last Modified: 2011-08-18
I have this piece of code.

printf("Exiting .");
sleep(1);
printf(" .");
sleep(1);
printf(" .");
sleep(1);
printf(" .");
sleep(1);
printf(" .");


I want to produce some sort of animation but then it does not seem to work as expected in unix/linux. The code works fine on windows. How to make that work in unix/linux?


hongjun
0
Comment
Question by:hongjun
  • 3
4 Comments
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
on windows sleep is in milliseconds and on linux it is in seconds ...
use usleep or nanosleep to achieve what you want
0
 
LVL 33

Author Comment

by:hongjun
Comment Utility
I am aware of the differences b/w windows and linux and that's why I do a sleep(1). I am trying to do this animation
Exiting .
ONE SECOND LATER
Exiting . .
ONE SECOND LATER
Exiting . . .
ONE SECOND LATER
....
.....


hongjun
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 50 total points
Comment Utility
Ok then I guess you are not getting the format as you expect... (dot by dot)
if yes, then you need to either flush the buffers or turn off buffering

printf("Exiting .");
fflush(stdout);
sleep(1);
printf(" .");
fflush(stdout);
sleep(1);
printf(" .");
fflush(stdout);
sleep(1);
printf(" .");
fflush(stdout);
sleep(1);
printf(" .");
fflush(stdout);
0
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
the above code will flush the buffers
to turn off buffering, refer to this
http://oldlook.experts-exchange.com/Programming/Programming_Platforms/Linux_Programming/Q_20675234.html
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now