$cmd="myCommand"; # Timeout evaluation: eval { # Set action to be done when alarm occurs: local $SIG{ALRM} = sub { die "ALARM_COMMAND_TIMEOUT" }; # Schedule alarm in $CMD_TIMEOUT seconds: alarm($CMD_TIMEOUT); ### execute the command that can block $childPID = open(PIPE, "-|"); ### Unable to create child process unless(defined $childPID) { close(PIPE); die "ERROR_FORK_PROCESS: $!\n"; } ### Child Process Created ... execute command unless($childPID) { exec($cmd) or die "ERROR_OPEN_PIPE : $!\n"; ### Unable to create child process } wait; alarm(0); close(PIPE); }; alarm(0);