source: tags/arb-6.0/SH/arb_rexec

Last change on this file was 7619, checked in by westram, 13 years ago
  • Property svn:executable set to *
File size: 1.2 KB
Line 
1#!/bin/bash
2
3execdate() {
4    local FILE=$1
5    date -r $FILE +%s
6}
7
8havejobs() {
9    jobs | wc -l
10}
11
12wait_term_or_recompile() {
13    local EXECUTABLE=$1
14    local PID=$2
15    local THAN=$3
16    local CURR=$THAN
17    local RUNNING=`havejobs`
18   
19    while [ $RUNNING -ne 0 ]; do
20        jobs >/dev/null # needed - whyever!
21        # echo "RUNNING=$RUNNING"
22        sleep 1
23        CURR=`execdate $EXECUTABLE`
24        if [ $CURR -gt $THAN ]; then
25            kill -9 $PID
26        fi
27        RUNNING=`havejobs`
28    done
29}
30
31# --------------------
32
33main() {
34    local EXECUTABLE=`which $1`
35    shift
36    local ARGS=$*
37
38    if [ -z "$EXECUTABLE" ]; then
39        echo "arb_rexec executable [arguments]"
40        echo "Debugging script."
41        echo "Calls 'executable'."
42        echo "When 'executable' terminates -> call it again."
43        echo "When 'executable' changes timestamp -> kill and call it again."
44    else
45        while true; do
46            echo calling $EXECUTABLE $ARGS
47            local STAMP=`execdate $EXECUTABLE`
48            $EXECUTABLE $ARGS &
49            local PID=$!
50            sleep 5
51            wait_term_or_recompile $EXECUTABLE $PID $STAMP
52        done
53    fi
54}
55
56main $*
Note: See TracBrowser for help on using the repository browser.