public void Start() { Log.Info("Watchdog starting..."); WatchdogState ws = WatchdogState.Create(); watchList = new HashSet <string>(); watchdogWorkerCb = new WaitCallback(WatchdogWorkerRoutine); watchList.Add("view"); watchList.Add("index"); watchList.Add("add"); WatchdogTimerState wts = new WatchdogTimerState(ws); this.wts = wts; workTimer = new Timer(new TimerCallback(Check), wts, 10 * 1000, 30 * 1000); Log.Info("Watchdog started"); }
private void WatchdogWorkerRoutine(object obj) { WatchdogState ws = (WatchdogState)obj; IEnumerable <Process> stillWorkingList; if (ws.IsFirstTaken) { SnapshotProcesses(ws.SecondSnapshot); stillWorkingList = Intersect(ws); if (stillWorkingList != null) { Log.Warning("There is {0} process(es) being hung", stillWorkingList.Count()); KillList(stillWorkingList); } else { Log.Info("There is no hang process."); } ws.Release(); ws = null; } }
public static WatchdogState Create() { WatchdogState ws = new WatchdogState(); ws.FirstSnapshot = new List <Process>(); ws.SecondSnapshot = new List <Process>(); return(ws); }
private IEnumerable <Process> Intersect(WatchdogState ws) { if (ws.FirstSnapshot.Count == 0) { yield break; } foreach (var fsp in ws.FirstSnapshot) { foreach (var ssp in ws.SecondSnapshot) { if (fsp.ProcessName.ToLower() == ssp.ProcessName.ToLower()) { yield return(fsp); break; } } } }
private void Check(object obj) { WatchdogTimerState wts = (WatchdogTimerState)obj; if (!wts.Ws.IsFirstTaken) { SnapshotProcesses(wts.Ws.FirstSnapshot); if (wts.Ws.FirstSnapshot.Count > 0) { wts.Ws.IsFirstTaken = true; Recalibrate(5 * 1000); } } else { WatchdogState prevWs = wts.Ws; wts.Change(WatchdogState.Create()); ThreadPool.QueueUserWorkItem(watchdogWorkerCb, prevWs); Recalibrate(30 * 1000); } }
public WatchdogState Change(WatchdogState newWs) { return(Interlocked.Exchange <WatchdogState>(ref ws, newWs)); }
public WatchdogTimerState(WatchdogState ws) { this.ws = ws; }