?
Solved

Sleep Function

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

771 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