#!/usr/bin/perl -w

eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
    if 0; # not running under some shell

=head1 NAME

timed-process - Run background process for limited amount of time

=head1 SYNOPSIS

    timed-process timeout path_to_program [<arg>...]

=head1 DESCRIPTION

This script runs a program for a specified amount of time and if it
doesn't finish, it kills the process.  This script requires the
complete pathname to the program to run and any optional arguments.
The program returns the exit status of the executed program.

=cut

use strict;
use Proc::Generic qw(timeout_system);
use Getopt::Long;

$0 =~ s:.*/::;

sub usage {
  print <<END;
Usage: $0 timeout path_to_program [<arg>...]

This script runs a program for a specified amount of time and if it
doesn't finish, it kills the process.  This script requires the
complete pathname to the program to run and any optional arguments.
The program returns the exit status of the executed program.
END
  exit 1;
}

@ARGV > 1 or usage;

print "@ARGV\n";

exit timeout_system(@ARGV);

