Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProcessTracker"/> class from the
        /// specified process id.
        /// </summary>
        /// <param name="parentProcess">
        /// The process whose descendants are to be tracked.
        /// </param>
        /// <param name="procDump">
        /// Object responsible for producing memory dumps of any tracked processes that
        /// fail or are terminated.
        /// </param>
        internal ProcessTracker(Process parentProcess, ProcDump procDump)
        {
            _parentProcess    = parentProcess;
            _trackedProcesses = new List <TrackedProcess>();
            _procDump         = procDump;

            TrackProcess(parentProcess);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProcessTracker"/> class from the
        /// specified process id.
        /// </summary>
        /// <param name="parentProcess">
        /// The process whose descendants are to be tracked.
        /// </param>
        /// <param name="procDump">
        /// Object responsible for producing memory dumps of any tracked processes that
        /// fail or are terminated.
        /// </param>
        internal ProcessTracker(Process parentProcess, ProcDump procDump)
        {
            _parentProcess = parentProcess;
            _trackedProcesses = new List<TrackedProcess>();
            _procDump = procDump;

            TrackProcess(parentProcess);
        }
Ejemplo n.º 3
0
        private int Run()
        {
            if (_options.TimeLimit <= 0)
            {
                ConsoleUtils.LogError(Resources.ErrorInvalidTimeLimit, _options.TimeLimit);
                return(1);
            }

            _timeLimit = TimeSpan.FromSeconds(_options.TimeLimit);

            if (_options.PollingInterval <= 0)
            {
                ConsoleUtils.LogError(Resources.ErrorInvalidPollingInterval, _options.PollingInterval);
                return(1);
            }

            if (!File.Exists(_options.ProcDumpPath))
            {
                ConsoleUtils.LogError(Resources.ErrorProcDumpNotFound, _options.ProcDumpPath);
                return(1);
            }

            var processStartInfo = new ProcessStartInfo
            {
                FileName  = _options.Executable,
                Arguments = _options.Arguments
            };

            Process  parentProcess = Process.Start(processStartInfo);
            ProcDump procDump      = new ProcDump(_options.ProcDumpPath, _options.OutputFolder);

            using (ProcessTracker processTracker = new ProcessTracker(parentProcess, procDump))
            {
                while (!processTracker.AllFinished)
                {
                    if (DateTime.Now - parentProcess.StartTime > _timeLimit)
                    {
                        ConsoleUtils.LogError(
                            Resources.ErrorProcessTimedOut,
                            _options.Executable,
                            parentProcess.Id,
                            _options.TimeLimit);

                        if (_options.Screenshot)
                        {
                            ScreenshotSaver.SaveScreen(_options.Executable, _options.OutputFolder);
                        }

                        processTracker.TerminateAll();
                        return(1);
                    }

                    Thread.Sleep(_options.PollingInterval);

                    processTracker.Update();
                }

                ConsoleUtils.LogMessage(
                    Resources.ProcessExited,
                    _options.Executable,
                    parentProcess.ExitTime - parentProcess.StartTime);
            }

            return(0);
        }
Ejemplo n.º 4
0
        private int Run()
        {
            if (_options.TimeLimit <= 0)
            {
                ConsoleUtils.LogError(Resources.ErrorInvalidTimeLimit, _options.TimeLimit);
                return 1;
            }

            _timeLimit = TimeSpan.FromSeconds(_options.TimeLimit);

            if (_options.PollingInterval <= 0)
            {
                ConsoleUtils.LogError(Resources.ErrorInvalidPollingInterval, _options.PollingInterval);
                return 1;
            }

            if (!File.Exists(_options.ProcDumpPath))
            {
                ConsoleUtils.LogError(Resources.ErrorProcDumpNotFound, _options.ProcDumpPath);
                return 1;
            }

            var processStartInfo = new ProcessStartInfo
            {
                FileName = _options.Executable,
                Arguments = _options.Arguments
            };

            Process parentProcess = Process.Start(processStartInfo);
            ProcDump procDump = new ProcDump(_options.ProcDumpPath, _options.OutputFolder);

            using (ProcessTracker processTracker = new ProcessTracker(parentProcess, procDump))
            {
                while (!processTracker.AllFinished)
                {
                    if (DateTime.Now - parentProcess.StartTime > _timeLimit)
                    {
                        ConsoleUtils.LogError(
                            Resources.ErrorProcessTimedOut,
                            _options.Executable,
                            parentProcess.Id,
                            _options.TimeLimit);

                        if (_options.Screenshot)
                        {
                            ScreenshotSaver.SaveScreen(_options.Executable, _options.OutputFolder);
                        }

                        processTracker.TerminateAll();
                        return 1;
                    }

                    Thread.Sleep(_options.PollingInterval);

                    processTracker.Update();
                }

                ConsoleUtils.LogMessage(
                    Resources.ProcessExited,
                    _options.Executable,
                    parentProcess.ExitTime - parentProcess.StartTime);
            }

            return 0;
        }