in reply to killing a program called with system() if it takes too long?

See system call with time out. There are other ways too, if you want to use an event loop, or thread for a timer, but alarm is usually what you are after. An old example:
#!/usr/bin/perl use strict; use warnings; my $timeout = 180; my @array = ( "command 1 goes here", "command 2 goes here", "command 3 goes here", ); for (@array) { eval { local $SIG{ALRM} = sub { die "alarm\n"; }; alarm $timeout; system($_); alarm 0; }; } # abigail says # Don't do it with system directly, or you might generate zombies. # fork(), do an exec() in the child, and then, in an eval block, # setup an alarm handler that does a die(), set the alarm, # waitpid() for your child, cancel the alarm. Outside the eval # block, check for $@, if it indicates the alarm was triggered, # kill the child and waitpid() for it. # No doubt there are some race conditions left in, but it's a start.

I'm not really a human, but I play one on earth Remember How Lucky You Are