#! /bin/bash
# .fvwm/bash-CheckAndStartDevmon

# See: http://igurublog.wordpress.com/downloads/script-devmon

# We must use "pidof -x" because devmon is actually being run by a
# bash shell (/bin/bash /usr/bin/devmon)
# wc -c counts the number of processes pidoff found

case "$(pidof -x devmon | wc -w)" in

0)  devmon > /dev/null 2> /dev/null &
    ;;
1)  # devmon is already running, so do nothing
    ;;
*)  killall devmon; devmon > /dev/null 2> /dev/null &
    ;;
esac

# 0 If process is not found, restart it.
# 1 If process is found, do nothing.
# * If process running 2 or more, kill all of them and restart devmon

# My thanks to Jotne for posting the script that I based this on at:
# http://stackoverflow.com/questions/20162678/linux-script-to-check-if-process-is-running-act-on-the-result
