how to terminate an external program after timeout?