I have a Perl script on a *nix system which, at one point, is processing 50,000 + lines of text. This takes some time. I am trying to find a resource friendly way to let the user know the program is not hanging while it is processing all of this text.

Currently I am printing output in realtime as the text is being processed . I am flushing the output buffer then printing the output on one line with \r. This seems to be an unnecessary use of resources because it takes almost twice as long than when I print nothing, but as I have said, when printing nothing it looks like the program is hanging.

So my question: Is there a standard or simple way to let the user know the program is indeed running while performing long running tasks?

  • Which unix? If it is FreeBSD then you can check if it is still busy by sending Control-T (Which is the default Status command).
    – Hennes
    Commented Oct 31, 2013 at 14:41

2 Answers 2


[I just realized your script is perl, but the same logic applies, print "\r", etc. You will want to use STDERR or else turn off buffering, $| = 1. See bottom.]

One way of implementing a CLI "progress indicator" involves the use of the \r (carriage return) character. This brings the cursor to the beginning of the current line:


while ((1)); do
    echo -ne "\rCount: $count"
    sleep 1;

If it doesn't make sense, just try it.

You could use that technique to indicate how many lines, or thousands of lines, have been processed so far. Tens or hundreds of lines may be good since it is not too often (more updates == slower runtime) but probably still often enough to show progress is continuing. You can specify a unit or just append zeros.

Note the use of -n and -e with echo, that is important.

You can also use \b (backspace) to similar effect.

In perl:

use strict;
use warnings FATAL => qw(all);

$| = 1;  # Pipeline stdout (i.e., no buffering).

my $count = 1;
while ($count) {
    print "\rCount $count";
    sleep 1;

Print out a single . without echoing a newline as you process. Age old technique.

So you get:


Simple and effective.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .