synchronized void handleWatchdog() {
      final int exitCode;

      if (watchdog == null)
        return;
      if (watchdogTimeout == 0)
        return;

      if (!isRunning()) {
        exitCode = ShellExitCode.SHELL_DIED;
      } else if (watchdogCount++ < watchdogTimeout) {
        return;
      } else {
        exitCode = ShellExitCode.WATCHDOG_EXIT;
      }

      if (handler != null) {
        postCallback(command, exitCode, buffer);
      }

      // prevent multiple callbacks for the same command
      command = null;
      buffer = null;
      idle = true;

      watchdog.shutdown();
      watchdog = null;
      kill();
    }
Called from a ScheduledThreadPoolExecutor timer thread every second when there is an outstanding command
imitate/src/main/java/com/engineer/imitate/shell/Shell.java