#!/usr/bin/perl -w
######################################################################
# tkfork.pl
######################################################################
# Perl Power! - Michael Schilli 1998
######################################################################

use Tk;
use Process;

my $topwindow = MainWindow->new();

                        # button with long-running callback
$button = $topwindow->Button(-text => "Press to Start", 
                             -command => \&takes_long);

$labeltext = "READY";

$label = $topwindow->Label("-textvariable", \$labeltext);

$button->pack();
$label->pack();

$proc = Process->new(); # create process object

MainLoop;

# long-running subroutine
sub takes_long {     

                   # start background process
    $proc->start(sub { sleep 5; });

                   # intercept returning child
    $SIG{CHLD} = sub { wait; $labeltext = "READY"; };

                   # display status
    $labeltext = "BUSY";
}

