in reply to How to kill an external program

Something like this works for me. I'm not doing any process clean-up; this is mainly so you can see how I'm doing it:
use POSIX qw/setsid/; $pid = fork(); if (!$pid) { setsid; # set our pgid to $$ system("sleep 30"); # just an example, put your xterm here } elsif (defined($pid)) { $SIG{ALRM} = sub { kill 'TERM', -$pid }; alarm 3; # .. do some stuff that will take longer than 3 seconds }
This will kill the child process and the sleep (whatever you put in the system call) after 3 seconds. The negative $pid on Solaris at least kills the process group referenced by $pid. Since we called setsid() earlier, that will kill the Perl child and whatever else that child spawned. You can trap $SIG{TERM} in the child if you want to catch it and do your own cleanup in Perl before exiting, though the sleep in this case will be killed regardless of this trap, since it receives the signal independently.