
use PersistentPerl;

my $pp = PersistentPerl->new;

my $method = ($ARGV[1] == 1) ? 'add_shutdown_handler' : 'set_shutdown_handler';
$pp->$method(sub {open(F, ">$ARGV[0]")});

BEGIN {
    $SIG{TERM} = IGNORE;
}

if ($ARGV[1] == 2) {
    $pp->shutdown_next_time();
}
elsif ($ARGV[1] == 3) {
    $pp->shutdown_now();
}

print $$;
