/// <summary> /// The default process limit handler. /// </summary> /// <param name="limits">The process limits.</param> /// <param name="message">The error message.</param> internal static void DefaultLimitHandler(ProcessLimits limits, string message) { // Add diagnostic information about each thread in the process, // including the stack trace, to the error message. // $todo(jeff.lill): // // There isn't a way to get the managed threads for the current // AppDomain so I'm going to punt on the additional diagnostics // for now. // // One place to look is the Managed Stack Explorer project // on CodePlex. This may have a low-level way of doing this. // We're going to log the error and then give the logging // system some additional time to flush it to persistent // storage before terminating the process. SysLog.LogError(message); SysLog.Flush(); Thread.Sleep(LogFlushInterval); limits.Process.Kill(); }
/// <summary> /// Adds a new process limitation to be monitored. /// </summary> /// <param name="processLimits">The process limitation information.</param> /// <remarks> /// This method silently ignores the addition of new limits for a process /// that is already being monitored. /// </remarks> public static void Add(ProcessLimits processLimits) { lock (syncLock) { foreach (var limit in limits) { if (limit.Process == processLimits.Process) { return; // We already have a limit for this process. } } limits.Add(processLimits); // Start the polling thread if it is not already running. if (pollThread == null) { pollThread = new Thread(new ThreadStart(PollLimits)); pollThread.Name = "LillTek-ProcessLimiter"; pollThread.Start(); } } }
/// <summary> /// Stops monitoring a process for limits. /// </summary> /// <param name="processLimits">The limitation information.</param> public static void Remove(ProcessLimits processLimits) { Remove(processLimits.Process); }