[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Sleep Function

Posted on 2003-11-07
4
Medium Priority
?
38,036 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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

649 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