~vcs-imports/junkcode/main

« back to all changes in this revision

Viewing changes to waitpid.sh

  • Committer: tridge
  • Date: 2007-02-27 00:31:28 UTC
  • Revision ID: vcs-imports@canonical.com-20070227003128-8ea2470f908182c6
add example usage

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
2
 
3
3
 
 
4
# wait for a pid with given timeout
 
5
# returns 1 if it timed out, 0 if the process exited itself
4
6
waitforpid() {
5
7
    pid=$1
6
8
    timeout=$2 # in seconds
9
11
        sleep 1;
10
12
        wcount=`expr $wcount + 1`
11
13
        if [ $wcount -eq $timeout ]; then
12
 
            break;
 
14
            return "1";
13
15
        fi
14
16
    done
 
17
    return "0";
15
18
}
16
19
 
17
 
waitforpid $1 $2
 
20
if `waitforpid $1 $2`; then
 
21
    echo "process $1 exited"
 
22
else
 
23
    echo "process $1 timed out"
 
24
fi