php shell_exec, exec command timeout

HI,

Does anybody know if its possible to execute a command through exec,
shell exec, system and if the program doesn't terminate in N seconds
returns control to PHP ?

reg,
research3

---------- Post updated 10-16-09 at 12:20 AM ---------- Previous update was 10-15-09 at 11:03 PM ----------

one of the solutions is:

<?php
exec("comand & sleep 3 ; kill $!");
?>

Seems reasonable to me, but I'd do this:

exec("comand && (sleep 3 ; kill -TERM $!; sleep 1; kill -9 $!)");

This mimics the usual shutdown sequence: give the process a change to die gracefully (-TERM) but if it hangs, terminate with extreme prejudice (-9).