Solved

Sleep Function

Posted on 2003-11-07
4
38,033 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
[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
  • 3
4 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9706104
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
ID: 9706621
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
ID: 9706626
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
ID: 9706635
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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

695 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