?
Solved

Problem using sleep

Posted on 2003-03-24
5
Medium Priority
?
170 Views
Last Modified: 2010-03-05
I have encountered a strange problem using the sleep builtin function.

Here is a REALLY simple program that demonstrates the issue

#!/usr/bin/perl

while(1) {
 print "hi\n";
 sleep 1;
}

This program hangs indefinitely. Hi is not printed out. Remove the call to sleep() and the program, as expected, endlessly prints hi. I have tried sleep(1), but to no avail.

I am using perl 5.8.0 on redhat 8.0 - 2.4.18-26.8.0smp.

This makes NO sense.
0
Comment
Question by:edschmoe
[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
5 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1000 total points
ID: 8199068
Try setting
$| = 1;
0
 
LVL 3

Expert Comment

by:prady_21
ID: 8199627
Just give the sleep before the print "Hi"; statement and it will work fine
:> Hope that helps
0
 
LVL 3

Expert Comment

by:prady_21
ID: 8199644
Anyway your program is working perfectly fine with my system too :>
0
 
LVL 48

Expert Comment

by:Tintin
ID: 8199799
Solution as ozo proposed.

The output is being buffered.

perldoc -q buffer
0
 

Author Comment

by:edschmoe
ID: 8199983
Thanks, flushing output worked!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

800 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