source: CDB_driver/trunk/lib/parallel_ramdisk.sh @ 36

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CDB_driver/trunk/lib/parallel_ramdisk.sh@36
Revision 36, 1.5 KB checked in by lalibert, 9 years ago (diff)

Initial import. This splits the driver from the diagnostics.

Line 
1#!/bin/bash
2
3wait_pid=${1}
4
5export RAM_TEMP_DIR=${2}
6
7##############################################################################
8#RAMDISK PROTECTION  ---  DO NOT CHANGE ANYTHING BELOW THIS LINE
9##############################################################################
10function trap_term {
11    echo -n "Trapped term (soft kill) signal on "
12    date
13    rm -rf ${RAM_TEMP_DIR}
14    kill -s TERM $PPID
15    exit
16}
17 
18function interruptible_sleep {
19    # waits for a number of seconds
20    # argument 1 = number of seconds
21    # note: just doing \`sleep \$1\' would not be interruptible!
22    for m in `seq $1`; do 
23        sleep 1
24    done
25}
26 
27function is_running {
28    # check if one or more process is running
29    # argument 1 = a command separated list of PIDs (no spaces)
30    ps -o pid= -p $1 | wc -l
31}
32
33poll_period=15        # how often check for job completion (in seconds)
34save_period=240       # how often to save output (in minutes)
35
36#trap the termination signal, and call the function 'trap_term' when
37# that happens, so results may be saved.
38trap "trap_term" TERM
39 
40#number of pollings per save period (rounded down):
41npoll=$(($save_period*60/$poll_period))
42 
43#polling and saving loop
44running=$(is_running $wait_pid)
45while [ $running -gt 0 ]
46do
47    for n in `seq $npoll`
48    do
49        interruptible_sleep $poll_period
50        running=$(is_running $wait_pid)
51    if [ $running -eq 0 ]; then
52        break
53    fi
54    done
55    echo -n "Waiting... "
56#save_results
57done
58     
Note: See TracBrowser for help on using the repository browser.