use strict; use warnings; use POSIX; use constant TIMEOUT => 20; my $firefox; unless ($firefox = fork) { die "Failed to fork: $!" unless (defined $firefox); exec '/woimmer/ich/bin/firefox', 'http://www.example.com/'; die "Failed to spawn firefox: $!"; } else { # remember time the browser was started my $start = time; my $remaining = TIMEOUT; # only loop while the browser is still running and the timeout is not over while (waitpid($firefox, WNOHANG) < 0 and $remaining > 0) { sleep $remaining; $remaining = $start + TIMEOUT - time; } # send the browser a TERM signal kill TERM => $firefox; # clean up the zombie process die "Problems cleaning up the browser process: $!" if (waitpid($firefox, 0) < 0); }