icius has asked for the wisdom of the Perl Monks concerning the following question:
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Child reading from Parent
by Jenda (Abbot) on Feb 19, 2003 at 23:42 UTC | |
by icius (Sexton) on Feb 20, 2003 at 00:19 UTC | |
by icius (Sexton) on Feb 20, 2003 at 00:25 UTC | |
by Jenda (Abbot) on Feb 20, 2003 at 13:57 UTC | |
|
Re: Child reading from Parent
by perrin (Chancellor) on Feb 19, 2003 at 22:57 UTC | |
by steves (Curate) on Feb 20, 2003 at 00:12 UTC | |
by perrin (Chancellor) on Feb 20, 2003 at 01:45 UTC | |
by steves (Curate) on Feb 20, 2003 at 02:42 UTC | |
|
Re: Child reading from Parent
by steves (Curate) on Feb 19, 2003 at 22:51 UTC |