sub exec_safe { my @cmd; # Return variable eval { local $SIG{ALRM} = sub { die "Timeout\n" }; alarm $_[1]; @cmd = `nice -n $_[2] $_[0]`; alarm 0; }; if($@) { # If command fails, return non-zero and msg return ("Command timeout",1); } else { chomp @cmd; push(@cmd,$? >> 8); return @cmd; } }