<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package ourfork;

sub safefork {
    local($time, $subname, @args) = @_;
    $subname = "main'" . $subname;
      FORK: {
	  if ($pid = fork) {
	      # parent here
	      sleep($time); # seconds
	      kill 9, $pid;
	  } elsif (defined $pid) {
	      # child here
	      &amp;$subname(@args);
	  } elsif ($! =~ /No more process/) {
	      sleep 5;
	      redo FORK;
	  } else {
	      die "Can't fork: $!\n";
	  }
      }
}
1;

</pre></body></html>