// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
usingCommandLine;
namespaceProcessWatchdog
{
/// <summary>
/// Command line options for the ProcessWatchdog tool.
/// </summary>
internalclassOptions
{
[Option(
't',
"time-limit",
HelpText="Time limit in seconds.",
Required=true)]
publicintTimeLimit{get;set;}
[Option(
'e',
"executable",
HelpText="The executable to run.",
Required=true)]
publicstringExecutable{get;set;}
[Option(
'a',
"arguments",
HelpText="Command line arguments to pass to the executable, enclosed in quotes if necessary.")]
publicstringArguments{get;set;}
[Option(
'o',
"output-folder",
HelpText="Folder to which process dumps and screen shots will be written.",
Default=".")]
publicstringOutputFolder{get;set;}
[Option(
'p',
"polling-interval",
HelpText="Polling interval in milliseconds",
Default=1000)]
publicintPollingInterval{get;set;}
[Option(
'd',
"procdump-path",
HelpText="Path to the executable procdump.exe.",
Required=true)]
publicstringProcDumpPath{get;set;}
[Option(
's',
"screenshot",
HelpText="Take a screenshot of the terminated process.",
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Diagnostics;
usingSystem.Globalization;
usingSystem.Linq;
usingSystem.Management;
namespaceProcessWatchdog
{
/// <summary>
/// Keeps track of a process and all its descendants.
/// </summary>
internalclassProcessTracker:IDisposable
{
privatereadonlyProcess_parentProcess;
privateList<TrackedProcess>_trackedProcesses;
privatereadonlyProcDump_procDump;
/// <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
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
/// Looks up a localized string similar to The value {0} is not a valid polling interval. Please specify the polling interval as a positive number of milliseconds..
/// Looks up a localized string similar to The process {0} ({1}) or one of its descendants exceeded the time limit of {2} seconds. This process and all its descendants will be terminated..
<value>The process {0} ({1}) or one of its descendants exceeded the time limit of {2} seconds. This process and all its descendants will be terminated.</value>
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
usingSystem;
usingSystem.Diagnostics;
usingSystem.Globalization;
usingSystem.Management;
namespaceProcessWatchdog
{
/// <summary>
/// Represents a process whose identity is guaranteed to be unique across time.
/// </summary>
/// <remarks>
/// The integer id that Windows associates with each process is not guaranteed to be
/// unique across time. Windows "recycles" these process ids; that is after a process
/// with a given id has terminated, Windows might create another process with the
/// same id. To uniquely identify a process, we use the combination of the process id