~ salmonella-environment-setup (master) /scripts/linux/hunt-a.out.sh
Trap1#! /bin/sh
2
3## signal-tests sometimes keeps an a.out file running eating CPU. This
4## script detects when an a.out is hanging and kills it if necessary
5
6logfile="$HOME/salmonella/watchdog.log"
7
8aout_pid() {
9 echo "`ps ax | grep '\./[a]\.out' | awk '{print $1}'`"
10}
11
12
13# Here we check if the process coresponding to the a.out file is
14# running. If it is running, we just sleep and check again after some
15# time. If after the wating time it is still running, we just kill
16# it.
17
18sleep_time=15m
19
20pid=`aout_pid`
21if [ -z "$pid" ]; then
22 exit 0
23fi
24if grep -q salmonella /proc/$pid/environ; then
25 echo "[`date`] a.out found running. Sleeping for $sleep_time." >> $logfile
26 sleep $sleep_time
27else
28 exit 0
29fi
30
31pid=`aout_pid`
32if [ -z "$pid" ]; then
33 exit 0
34fi
35if grep -q salmonella /proc/$pid/environ; then
36 echo "[`date`] a.out still running after $sleep_time. Killing it." >> $logfile
37 kill -9 "$pid"
38fi