#!/usr/bin/perl
use strict;

my @child_pid;
my @grand_child_pid;

my $dir = $ENV{PWD};

foreach (1 .. 60 * 24 * 3) {
        #my @basename = (1 .. 10);
        chomp(my @basename = `ls -1 $dir/usr/libexec/xscreensaver`);

        foreach my $basename (@basename) {
                my $pid = fork;
                push(@child_pid, $pid);
                unless ($pid) {
                        my $pid = fork;
                        push(@grand_child_pid, $pid);
                        unless ($pid) {
                                #print "grand_child: $$\n";
                                #exec "./test", "$basename";
                                exec "$dir/usr/libexec/xscreensaver/$basename";
                        }
                        sleep 60;
                        #print "child: $pid\n";
                        kill 9, $pid;
                        exit;
                }
        }

        foreach (@child_pid) {
                waitpid($_, 0);
        }
}

#=pod
$SIG{HUP} = $SIG{INT} = $SIG{PIPE} = $SIG{QUIT} = $SIG{TERM} = \&unlock;
$SIG{'PIPE'} = $SIG{'INT'} = $SIG{'HUP'} = $SIG{'QUIT'} = $SIG{'TERM'} = \&signal_handler;
sub signal_handler {
        kill 9, @grand_child_pid;
        kill 9, @child_pid;
        exit;
}
#=cut

