better section detection
[tridge/junkcode.git] / waitpid.sh
1 #!/bin/sh
2
3
4 # wait for a pid with given timeout
5 # returns 1 if it timed out, 0 if the process exited itself
6 waitforpid() {
7     pid=$1
8     timeout=$2 # in seconds
9     _wcount=0
10     while kill -0 $pid 2> /dev/null; do
11         sleep 1;
12         _wcount=`expr $_wcount + 1`
13         if [ $_wcount -eq $timeout ]; then
14             return "1";
15         fi
16     done
17     return "0";
18 }
19
20 if `waitforpid $1 $2`; then
21     echo "process $1 exited"
22 else
23     echo "process $1 timed out"
24 fi