[Ilugc] Re : timeout in shell command

  • From: lug@xxxxxxxxxxxxxxxxxx (Chandrashekar Babu)
  • Date: Tue Sep 11 01:31:30 2007

Hi,

Amit Dey wrote:


now can i display a message if the process has completed successfully.
and for this i dont want to wait for 10 seconds. i want this message 
immediately after program termination
You can try the following snippet:

  ( ./binaryfilename ; echo "Process completed" ) &
  PID=$!
  sleep 10 && kill $PID && echo "Killed process $PID"

Note the ( ) in the first line. This invokes your program within
a sub-shell and runs the same in the background, after which
the 'echo "Process complete"' statement gets to run.

However, I'd recommend a && pipeline instead of ; command
separator on the first line, i.e., if your program follows the
standard UNIX convention of 'return 0' on success.

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

Other related posts: