use strict; $|++; my $stream = *STDOUT; my $thingy = [ "\\", "|", "/", "-" ]; my $rate = 0.175; my $step = 0; my $spin_stop = 0; FORK: { if( my $code_pid = fork() ) { sleep(5); $spin_stop = 1; } elsif( defined $code_pid ) { print "Process executing.."; _spin(); exit 0; } elsif( $! =~ /No more process/ ) { sleep 2; redo FORK; } else { die "ERROR: can't fork! $!"; } } print "\nProcess Complete\n"; sub _spin { SPIN: while(1) { my $old_fh = select($stream); local $| = 1; print $stream $$thingy[$step], chr(8) x length($$thingy[$step]); select($old_fh); $step = ( $step+1 > $#$thingy ? 0 : $step+1 ); select(undef,undef,undef, $rate); last SPIN if($spin_stop == 1); } return; }