[Ilugc] timeout in shell command

  • From: lug@xxxxxxxxxxxxxxxxxx (Chandrashekar Babu)
  • Date: Sun Sep 9 19:17:17 2007

Hi,

Amit Dey wrote:

Assume that i have to execute a binary file 
  so i do
  ./binaryfilename
Now there is a chance that the execution may run into 
an infinite loop.
   
What i want is that if the execution has not completed 
in 10 seconds then it should be aborted and i should 
get some kind of signal for incomplete execution.
Try this at the shell prompt (or add these lines into a
wrapper shell script):
    ./binaryfilename &
    PID=$!
    sleep 10 && kill $PID && echo "Killed process $PID"

Cheers!
-- 
Chandrashekar Babu,
FOSS Technologist,
http://www.chandrashekar.info/


Other related posts: