Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reverted use of JobObject

  • Loading branch information...
commit f1ec565575544396b0b2fcfbb73edbb51d2a7e0a 1 parent 43af92d
@lukebakken lukebakken authored
View
18 docs/licenses/uhuru_software.txt
@@ -1,18 +0,0 @@
--------------------- Uhuru Source Code ---------------------------------
-
-Copyright [2011] [Uhuru Software, Inc.]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO VENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.
View
3  src/IronFoundry.Dea/IronFoundry.Dea.csproj
@@ -164,9 +164,6 @@
<Compile Include="WcfInfrastructure\IocServiceHost.cs" />
<Compile Include="WcfInfrastructure\PerCallServiceHost.cs" />
<Compile Include="WcfInfrastructure\WcfWinService.cs" />
- <Compile Include="WindowsJobObjects\JobObject.cs" />
- <Compile Include="WindowsJobObjects\JobObjectHandle.cs" />
- <Compile Include="WindowsJobObjects\NativeMethods.cs" />
<Compile Include="WinService\MonitoringWinService.cs" />
<Compile Include="WinService\DeaWinService.cs" />
<Compile Include="WinService\FilesWinService.cs" />
View
31 src/IronFoundry.Dea/Types/Instance.cs
@@ -5,7 +5,6 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
- using IronFoundry.Dea.WindowsJobObjects;
using JsonConverters;
using Newtonsoft.Json;
@@ -19,18 +18,14 @@ public class Instance : EntityBase, IDisposable
private readonly DateTime instanceStartDate;
- private readonly JobObject jobObject = new JobObject();
+ private readonly IList<Process> workerProcesses = new List<Process>();
private readonly string logID;
private DateTime? workerProcessStartDate = null;
private bool isEvacuated = false;
- public Instance()
- {
- jobObject.DieOnUnhandledException = true;
- jobObject.ActiveProcessesLimit = 10;
- }
+ public Instance() { }
public Instance(string appDir, Droplet droplet) : this()
{
@@ -252,14 +247,21 @@ public void UpdateState(string argNewState)
public void AddWorkerProcess(Process newInstanceWorkerProcess)
{
if (false == newInstanceWorkerProcess.HasExited &&
- false == jobObject.HasProcess(newInstanceWorkerProcess))
+ false == workerProcesses.Contains(newInstanceWorkerProcess))
{
- jobObject.AddProcess(newInstanceWorkerProcess);
+ workerProcesses.Add(newInstanceWorkerProcess);
if (false == workerProcessStartDate.HasValue)
{
workerProcessStartDate = DateTime.Now;
}
}
+
+ var exitedProcesses = new List<Process>();
+ exitedProcesses.AddRange(workerProcesses.Where(wp => wp.HasExited));
+ foreach (var exited in exitedProcesses)
+ {
+ workerProcesses.Remove(exited);
+ }
}
[JsonIgnore]
@@ -288,9 +290,12 @@ public void CalculateUsage()
newUsage.DiskUsageBytes = GetDiskUsage(this.Dir);
- newUsage.MemoryUsageKB = jobObject.WorkingSetMemory / 1024;
+ long totalWorkerWorkingSet = workerProcesses.Sum(wp => wp.WorkingSet64);
+ long totalWorkerProcessorTime = workerProcesses.Sum(wp => wp.TotalProcessorTime.Ticks);
+
+ newUsage.MemoryUsageKB = totalWorkerWorkingSet / 1024;
- long currentTotalCpuTicks = newUsage.TotalCpuTicks = jobObject.TotalProcessorTime.Ticks;
+ long currentTotalCpuTicks = newUsage.TotalCpuTicks = totalWorkerProcessorTime;
DateTime currentTicksTimestamp = newUsage.Time = DateTime.Now;
Usage lastUsage = MostRecentUsage;
@@ -328,9 +333,9 @@ private void Dispose(bool disposing)
{
if (disposing)
{
- if (jobObject != null)
+ foreach (var process in workerProcesses)
{
- jobObject.Dispose();
+ process.Dispose();
}
}
}
View
1,024 src/IronFoundry.Dea/WindowsJobObjects/JobObject.cs
@@ -1,1024 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) 2011 Uhuru Software, Inc., All Rights Reserved
-// Copyright (c) 2012 Tier 3, Inc.
-// THE CONTENTS OF THE ORIGINAL FILE HAVE BEEN MODIFIED BY TIER 3
-// -----------------------------------------------------------------------
-
-namespace IronFoundry.Dea.WindowsJobObjects
-{
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Diagnostics.CodeAnalysis;
- using System.Runtime.InteropServices;
- using System.Security.Permissions;
-
- /// <summary>
- /// Is a class that manages a Windows Job Object. Job Objects allows to group a number of processes and
- /// perform some aggregate operations. It is a good tool for enforcing resource sandboxing for processes.
- /// </summary>
- [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Preserve WinAPI naming.")]
- [SecurityPermission(SecurityAction.LinkDemand), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2126:TypeLinkDemandsRequireInheritanceDemands", Justification = "Appropriate to suppress."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2135:SecurityRuleSetLevel2MethodsShouldNotBeProtectedWithLinkDemandsFxCopRule", Justification = "Appropriate to suppress.")]
- //// [SecurityCriticalAttribute]
- public class JobObject : IDisposable
- {
- /// <summary>
- /// The Windows Handle
- /// </summary>
- private JobObjectHandle jobHandle;
-
- /// <summary>
- /// Flag to kill processes on job close.
- /// </summary>
- private bool killProcessesOnJobClose = true;
-
- /// <summary>
- /// Die on unhandled exception.
- /// </summary>
- private bool dieOnUnhandledException = false;
-
- /// <summary>
- /// Allow child process breakaway.
- /// </summary>
- private bool allowChildProcessesBreakaway = false;
-
- /// <summary>
- /// Breakaway child processes by default.
- /// </summary>
- private bool alwaysBreakawayChildProcesses = false;
-
- /// <summary>
- /// Maximum number of active processes.
- /// </summary>
- private uint activeProcessesLimit = 0;
-
- /// <summary>
- /// The memory limit of the Job Object.
- /// </summary>
- private long jobMemoryLimit = 0;
-
- /// <summary>
- /// The memory limit of each process in the Job Object.
- /// </summary>
- private long processMemoryLimit = 0;
-
- /// <summary>
- /// Flag if the job processor user time limit has changed.
- /// </summary>
- private bool jobUserTimeLimitChanged = false;
-
- /// <summary>
- /// The processor user time limit for the job.
- /// </summary>
- private long jobUserTimeLimit = 0;
-
- /// <summary>
- /// The user time limit per each process in the job.
- /// </summary>
- private long processUserTimeLimit = 0;
-
- /// <summary>
- /// The priority class of the Job Object.
- /// </summary>
- private uint priorityClass = 0;
-
- /// <summary>
- /// The scheduling class.
- /// </summary>
- private uint schedulingClass = 0;
-
- /// <summary>
- /// The processor affinity.
- /// </summary>
- private IntPtr affinity = IntPtr.Zero;
-
- /// <summary>
- /// The read IO operations count for the whole job.
- /// </summary>
- private long ioReadOperationsCount = 0;
-
- /// <summary>
- /// The write IO operations count for the whole job.
- /// </summary>
- private long ioWriteOperationsCount = 0;
-
- /// <summary>
- /// Other IO operations count for the while job.
- /// </summary>
- private long ioOtherOperationsCount = 0;
-
- /// <summary>
- /// Total IO bytes read by the job.
- /// </summary>
- private long ioReadBytes = 0;
-
- /// <summary>
- /// Total IO bytes written by the job.
- /// </summary>
- private long ioWriteBytes = 0;
-
- /// <summary>
- /// Total IO bytes used in other operations.
- /// </summary>
- private long ioOtherBytes = 0;
-
- /// <summary>
- /// Peak memory usage by the job.
- /// </summary>
- private ulong peakJobMemory = 0;
-
- /// <summary>
- /// Peak memory usage by a process.
- /// </summary>
- private ulong peakProcessMemory = 0;
-
- /// <summary>
- /// Total user processor time used by the job.
- /// </summary>
- private ulong userProcessorTime = 0;
-
- /// <summary>
- /// Total kernel processor time used by the job.
- /// </summary>
- private ulong kernelProcessorTime = 0;
-
- /// <summary>
- /// The processes in the job.
- /// </summary>
- private Process[] jobProcesses;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="JobObject"/> class. The Windows Job Object is unnamed.
- /// </summary>
- public JobObject()
- : this(null)
- {
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="JobObject"/> class. If a Job Object with the specified name exists,
- /// then the Job Object is opened; if not, the Job Object with the specified named is opened.
- /// </summary>
- /// <param name="jobObjectName">Name of the job object.</param>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "CreateJobObject", Justification = "Appropriate to suppress."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "OpenJobObject", Justification = "Appropriate to suppress.")]
- public JobObject(string jobObjectName)
- {
- if (string.IsNullOrEmpty(jobObjectName))
- {
- jobObjectName = null;
- }
-
- this.jobHandle = NativeMethods.CreateJobObject(IntPtr.Zero, jobObjectName);
- if (this.jobHandle.IsInvalid)
- {
- if (jobObjectName == null)
- {
- int error = Marshal.GetLastWin32Error();
- throw new Win32Exception(error, "CreateJobObject failed.");
- }
- else
- {
- // JOB_OBJECT_ALL_ACCESS = 0x1F001F
- this.jobHandle = NativeMethods.OpenJobObject(0x1F001F, false, jobObjectName);
- if (this.jobHandle.IsInvalid)
- {
- int error = Marshal.GetLastWin32Error();
- throw new Win32Exception(error, "OpenJobObject failed.");
- }
- }
- }
-
- this.UpdateExtendedLimit();
- }
-
- /// <summary>
- /// Finalizes an instance of the JobObject class. Releases unmanaged resources and performs other cleanup operations before the
- /// <see cref="JobObject"/> is reclaimed by garbage collection.
- /// </summary>
- ~JobObject()
- {
- this.Dispose(false);
- }
-
- /// <summary>
- /// Gets or sets a value indicating whether to kill the processes when the Job Object is closed.
- /// </summary>
- /// <value>
- /// <c>true</c> if [kill processes on job close]; otherwise, <c>false</c>.
- /// </value>
- public bool KillProcessesOnJobClose
- {
- get
- {
- return this.killProcessesOnJobClose;
- }
-
- set
- {
- this.killProcessesOnJobClose = value;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets or sets a value indicating whether a process to die on an unhandled exception.
- /// </summary>
- /// <value>
- /// <c>true</c> if [die on unhandled exception]; otherwise, <c>false</c>.
- /// </value>
- public bool DieOnUnhandledException
- {
- get
- {
- return this.dieOnUnhandledException;
- }
-
- set
- {
- this.dieOnUnhandledException = value;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets or sets a value indicating whether processes are allowed to create processes outside the Job Object.
- /// </summary>
- /// <value>
- /// <c>true</c> if [allow child processes breakaway]; otherwise, <c>false</c>.
- /// </value>
- public bool AllowChildProcessesBreakaway
- {
- get
- {
- return this.allowChildProcessesBreakaway;
- }
-
- set
- {
- this.allowChildProcessesBreakaway = value;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets or sets a value indicating whether child processes are not added to the Job Object.
- /// </summary>
- /// <value>
- /// <c>true</c> if [always breakaway child processes]; otherwise, <c>false</c>.
- /// </value>
- public bool AlwaysBreakawayChildProcesses
- {
- get
- {
- return this.alwaysBreakawayChildProcesses;
- }
-
- set
- {
- this.alwaysBreakawayChildProcesses = value;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets or sets the active processes in the Job Object. Set to 0 (zero) to disable the limit.
- /// </summary>
- /// <value>
- /// The active processes.
- /// </value>
- public int ActiveProcessesLimit
- {
- get
- {
- return (int)this.activeProcessesLimit;
- }
-
- set
- {
- this.activeProcessesLimit = (uint)value;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets or sets the memory in bytes limit enforced per process. Set to 0 (zero) to disable the limit.
- /// </summary>
- /// <value>
- /// The process memory limit.
- /// </value>
- public long ProcessMemoryLimit
- {
- get
- {
- return (long)this.processMemoryLimit;
- }
-
- set
- {
- this.processMemoryLimit = (long)value;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets or sets the memory limit in bytes of the entire Job Object. Set to 0 (zero) to disable the limit.
- /// </summary>
- /// <value>
- /// The job memory limit.
- /// </value>
- public long JobMemoryLimit
- {
- get
- {
- return this.jobMemoryLimit;
- }
-
- set
- {
- this.jobMemoryLimit = value;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets or sets the process user time limit. It is enforced per process. Set to 0 (zero) to disable the limit.
- /// </summary>
- /// <value>
- /// The process user time limit.
- /// </value>
- public TimeSpan ProcessUserTimeLimit
- {
- get
- {
- return new TimeSpan(this.processUserTimeLimit);
- }
-
- set
- {
- this.processUserTimeLimit = value.Ticks;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets or sets the Job Object user time limit. Every process user time is accounted. Set to 0 (zero) to disable the limit.
- /// </summary>
- /// <value>
- /// The job user time limit.
- /// </value>
- public TimeSpan JobUserTimeLimit
- {
- get
- {
- return new TimeSpan(this.jobUserTimeLimit);
- }
-
- set
- {
- this.jobUserTimeLimit = value.Ticks;
- this.jobUserTimeLimitChanged = true;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets or sets the priority class of the Job Object.
- /// </summary>
- /// <value>
- /// The priority class.
- /// </value>
- public ProcessPriorityClass PriorityClass
- {
- get
- {
- return (ProcessPriorityClass)this.priorityClass;
- }
-
- set
- {
- this.priorityClass = (uint)value;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets or sets the scheduling class of the JobObject.
- /// </summary>
- /// <value>
- /// The scheduling class.
- /// </value>
- public int SchedulingClass
- {
- get
- {
- return (int)this.schedulingClass;
- }
-
- set
- {
- this.schedulingClass = (uint)value;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets or sets the processor affinity, enforced for every process.
- /// </summary>
- /// <value>
- /// The affinity.
- /// </value>
- public IntPtr Affinity
- {
- get
- {
- return this.affinity;
- }
-
- set
- {
- this.affinity = value;
- this.UpdateExtendedLimit();
- }
- }
-
- /// <summary>
- /// Gets the total IO bytes read by every process in the Job Object.
- /// </summary>
- public long IOReadBytes
- {
- get
- {
- this.QueryBasicAndIoAccounting();
- return this.ioReadBytes;
- }
- }
-
- /// <summary>
- /// Gets the total IO bytes written by every process in the Job Object.
- /// </summary>
- public long IOWriteBytes
- {
- get
- {
- this.QueryBasicAndIoAccounting();
- return this.ioWriteBytes;
- }
- }
-
- /// <summary>
- /// Gets the total IO bytes used in other operations by every process in the Job Object.
- /// </summary>
- public long IOOtherBytes
- {
- get
- {
- this.QueryBasicAndIoAccounting();
- return this.ioOtherBytes;
- }
- }
-
- /// <summary>
- /// Gets the IO read operations count preformed by every process in the Job Object.
- /// </summary>
- public long IOReadOperationsCount
- {
- get
- {
- this.QueryBasicAndIoAccounting();
- return this.ioReadOperationsCount;
- }
- }
-
- /// <summary>
- /// Gets the IO write operations count preformed by every process in the Job Object.
- /// </summary>
- public long IOWriteOperationsCount
- {
- get
- {
- this.QueryBasicAndIoAccounting();
- return this.ioWriteOperationsCount;
- }
- }
-
- /// <summary>
- /// Gets the other IO operations count preformed by every process in the Job Object.
- /// </summary>
- public long IOOtherOperationsCount
- {
- get
- {
- this.QueryBasicAndIoAccounting();
- return this.ioOtherOperationsCount;
- }
- }
-
- /// <summary>
- /// Gets the peak memory in bytes used by the Job Object at any given time.
- /// </summary>
- public long PeakJobMemory
- {
- get
- {
- this.QueryExtendedLimitInformation();
- return (long)this.peakJobMemory;
- }
- }
-
- /// <summary>
- /// Gets the peak memory in bytes used by a process.
- /// </summary>
- public long PeakProcessMemory
- {
- get
- {
- this.QueryExtendedLimitInformation();
- return (long)this.peakProcessMemory;
- }
- }
-
- /// <summary>
- /// Gets the total processor time used by each process.
- /// </summary>
- public TimeSpan TotalProcessorTime
- {
- get
- {
- this.QueryBasicAndIoAccounting();
- return new TimeSpan((long)this.userProcessorTime + (long)this.kernelProcessorTime);
- }
- }
-
- /// <summary>
- /// Gets the user processor time used by each process.
- /// </summary>
- public TimeSpan UserProcessorTime
- {
- get
- {
- this.QueryBasicAndIoAccounting();
- return new TimeSpan((long)this.userProcessorTime);
- }
- }
-
- /// <summary>
- /// Gets the kernel processor time used by each process.
- /// </summary>
- public TimeSpan KernelProcessorTime
- {
- get
- {
- this.QueryBasicAndIoAccounting();
- return new TimeSpan((long)this.kernelProcessorTime);
- }
- }
-
- /// <summary>
- /// Gets the working set memory in bytes of the Job Object.
- /// </summary>
- public long WorkingSetMemory
- {
- get
- {
- this.QueryProcessIds();
- long res = 0;
- foreach (Process p in this.jobProcesses)
- {
- res += p.WorkingSet64;
- }
-
- return res;
- }
- }
-
- /// <summary>
- /// Gets the virtual memory in bytes.
- /// </summary>
- public long VirtualMemory
- {
- get
- {
- this.QueryProcessIds();
- long res = 0;
- foreach (Process p in this.jobProcesses)
- {
- res += p.VirtualMemorySize64;
- }
-
- return res;
- }
- }
-
- /// <summary>
- /// Gets the private memory in bytes.
- /// </summary>
- public long PrivateMemory
- {
- get
- {
- this.QueryProcessIds();
- long res = 0;
- foreach (Process p in this.jobProcesses)
- {
- res += p.PrivateMemorySize64;
- }
-
- return res;
- }
- }
-
- /// <summary>
- /// Gets the paged memory in bytes.
- /// </summary>
- public long PagedMemory
- {
- get
- {
- this.QueryProcessIds();
- long res = 0;
- foreach (Process p in this.jobProcesses)
- {
- res += p.PagedMemorySize64;
- }
-
- return res;
- }
- }
-
- /// <summary>
- /// Gets the paged system memory in bytes.
- /// </summary>
- public long PagedSystemMemory
- {
- get
- {
- this.QueryProcessIds();
- long res = 0;
- foreach (Process p in this.jobProcesses)
- {
- res += p.PagedSystemMemorySize64;
- }
-
- return res;
- }
- }
-
- /// <summary>
- /// Gets the non paged system memory in bytes.
- /// </summary>
- public long NonPagedSystemMemory
- {
- get
- {
- this.QueryProcessIds();
- long res = 0;
- foreach (Process p in this.jobProcesses)
- {
- res += p.NonpagedSystemMemorySize64;
- }
-
- return res;
- }
- }
-
- /// <summary>
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- /// </summary>
- public void Dispose()
- {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- /// <summary>
- /// Adds a process to the current Job Object, for which the Job Object limits apply.
- /// </summary>
- /// <param name="process">The process to be added.</param>
- public void AddProcess(Process process)
- {
- if (process == null)
- {
- throw new ArgumentNullException("process");
- }
-
- this.AddProcess(process.Handle);
- }
-
- /// <summary>
- /// Determines whether the specified process is in the Job Object
- /// </summary>
- /// <param name="process">The process to be checked for.</param>
- /// <returns>
- /// <c>true</c> if the specified process has the process; otherwise, <c>false</c>.
- /// </returns>
- public bool HasProcess(Process process)
- {
- if (process == null)
- {
- throw new ArgumentNullException("process");
- }
-
- return this.HasProcess(process.Handle);
- }
-
- /// <summary>
- /// Terminates all the processes in the Job Object.
- /// </summary>
- /// <param name="exitCode">The exit code.</param>
- public void TerminateProcesses(int exitCode)
- {
- NativeMethods.TerminateJobObject(this.jobHandle, (uint)exitCode);
- }
-
- /// <summary>
- /// Gets all the processes included in the Job Object.
- /// </summary>
- /// <returns>The list of processes.</returns>
- public Process[] GetJobProcesses()
- {
- this.QueryProcessIds();
- return this.jobProcesses;
- }
-
- /// <summary>
- /// Releases unmanaged and - optionally - managed resources
- /// </summary>
- /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
- this.jobHandle.Close();
- }
- }
-
- /// <summary>
- /// Determines whether the specified process handle is included in the Job Object.
- /// </summary>
- /// <param name="processHandle">The process handle.</param>
- /// <returns>
- /// <c>true</c> if the specified process handle has process; otherwise, <c>false</c>.
- /// </returns>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "IsProcessInJob", Justification = "Appropriate to suppress.")]
- private bool HasProcess(IntPtr processHandle)
- {
- bool result;
- bool success = NativeMethods.IsProcessInJob(processHandle, this.jobHandle, out result);
- if (success == false)
- {
- int error = Marshal.GetLastWin32Error();
- throw new Win32Exception(error, "IsProcessInJob failed.");
- }
-
- return result;
- }
-
- /// <summary>
- /// Adds the process handle to the Job object.
- /// </summary>
- /// <param name="processHandle">The process handle.</param>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "AssignProcessToJobObject", Justification = "Appropriate to suppress.")]
- private void AddProcess(IntPtr processHandle)
- {
- bool success = NativeMethods.AssignProcessToJobObject(this.jobHandle, processHandle);
- if (success == false)
- {
- int error = Marshal.GetLastWin32Error();
- throw new Win32Exception(error, "AssignProcessToJobObject failed.");
- }
- }
-
- /// <summary>
- /// Queries the process ids.
- /// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "QueryInformationJobObject", Justification = "Appropriate to suppress.")]
- private void QueryProcessIds()
- {
- NativeMethods.JOBOBJECT_BASIC_PROCESS_ID_LIST processList = new NativeMethods.JOBOBJECT_BASIC_PROCESS_ID_LIST();
- processList.NumberOfAssignedProcesses = NativeMethods.JOBOBJECT_BASIC_PROCESS_ID_LIST.MaxProcessListLength;
- processList.NumberOfProcessIdsInList = 0;
- processList.ProcessIdList = null;
-
- int processListLength = Marshal.SizeOf(typeof(NativeMethods.JOBOBJECT_BASIC_PROCESS_ID_LIST));
- IntPtr processListPtr = Marshal.AllocHGlobal(processListLength);
-
- try
- {
- Marshal.StructureToPtr(processList, processListPtr, false);
-
- bool success = NativeMethods.QueryInformationJobObject(this.jobHandle, NativeMethods.JobObjectInfoClass.JobObjectBasicProcessIdList, processListPtr, (uint)processListLength, IntPtr.Zero);
-
- if (success == false)
- {
- int error = Marshal.GetLastWin32Error();
- throw new Win32Exception(error, "QueryInformationJobObject failed.");
- }
-
- processList = (NativeMethods.JOBOBJECT_BASIC_PROCESS_ID_LIST)Marshal.PtrToStructure(processListPtr, typeof(NativeMethods.JOBOBJECT_BASIC_PROCESS_ID_LIST));
-
- List<Process> pss = new List<Process>();
-
- for (int i = 0; i < processList.NumberOfProcessIdsInList; i++)
- {
- try
- {
- pss.Add(Process.GetProcessById((int)processList.ProcessIdList[i]));
- }
- catch (ArgumentException)
- {
- }
- }
-
- this.jobProcesses = pss.ToArray();
- }
- finally
- {
- Marshal.FreeHGlobal(processListPtr);
- }
- }
-
- /// <summary>
- /// Updates the extended limit.
- /// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "SetInformationJobObject", Justification = "Appropriate to suppress.")]
- private void UpdateExtendedLimit()
- {
- NativeMethods.JOBOBJECT_EXTENDED_LIMIT_INFORMATION extendedLimit = new NativeMethods.JOBOBJECT_EXTENDED_LIMIT_INFORMATION();
- NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION basicLimit = new NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION();
-
- basicLimit.LimitFlags = 0;
-
- if (this.killProcessesOnJobClose)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
- }
-
- if (this.dieOnUnhandledException)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION;
- }
-
- if (this.allowChildProcessesBreakaway)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_BREAKAWAY_OK;
- }
-
- if (this.alwaysBreakawayChildProcesses)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK;
- }
-
- if (this.activeProcessesLimit != 0)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_ACTIVE_PROCESS;
- basicLimit.ActiveProcessLimit = this.activeProcessesLimit;
- }
-
- if (this.processMemoryLimit != 0)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_PROCESS_MEMORY;
- extendedLimit.ProcessMemoryLimit = (IntPtr)this.processMemoryLimit;
- }
-
- if (this.jobMemoryLimit != 0)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_JOB_MEMORY;
- extendedLimit.JobMemoryLimit = (IntPtr)this.jobMemoryLimit;
- }
-
- if (this.processUserTimeLimit != 0)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_PROCESS_TIME;
- basicLimit.PerProcessUserTimeLimit = this.processUserTimeLimit;
- }
-
- if (this.jobUserTimeLimit != 0)
- {
- if (this.jobUserTimeLimitChanged)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_JOB_TIME;
- basicLimit.PerJobUserTimeLimit = this.jobUserTimeLimit;
- this.jobUserTimeLimitChanged = false;
- }
- else
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME;
- }
- }
-
- if (this.priorityClass != 0)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_PRIORITY_CLASS;
- basicLimit.PriorityClass = this.priorityClass;
- }
-
- if (this.schedulingClass != 0)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_SCHEDULING_CLASS;
- basicLimit.SchedulingClass = this.schedulingClass;
- }
-
- if (this.affinity != IntPtr.Zero)
- {
- basicLimit.LimitFlags |= NativeMethods.JOBOBJECT_BASIC_LIMIT_INFORMATION.JOB_OBJECT_LIMIT_AFFINITY;
- basicLimit.Affinity = this.affinity;
- }
-
- extendedLimit.BasicLimitInformation = basicLimit;
-
- int extendedLimitLength = Marshal.SizeOf(typeof(NativeMethods.JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
- IntPtr extendedLimitPtr = Marshal.AllocHGlobal(extendedLimitLength);
-
- try
- {
- Marshal.StructureToPtr(extendedLimit, extendedLimitPtr, false);
-
- bool success = NativeMethods.SetInformationJobObject(this.jobHandle, NativeMethods.JobObjectInfoClass.JobObjectExtendedLimitInformation, extendedLimitPtr, (uint)extendedLimitLength);
-
- if (success == false)
- {
- int error = Marshal.GetLastWin32Error();
- throw new Win32Exception(error, "SetInformationJobObject failed.");
- }
- }
- finally
- {
- Marshal.FreeHGlobal(extendedLimitPtr);
- }
- }
-
- /// <summary>
- /// Queries the basic and IO accounting.
- /// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "QueryInformationJobObject", Justification = "Appropriate to suppress.")]
- private void QueryBasicAndIoAccounting()
- {
- NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION accounting = new NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION();
- accounting.BasicInfo = new NativeMethods.JOBOBJECT_BASIC_ACCOUNTING_INFORMATION();
- accounting.IoInfo = new NativeMethods.IO_COUNTERS();
-
- int accountingLength = Marshal.SizeOf(typeof(NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION));
- IntPtr accountingPtr = Marshal.AllocHGlobal(accountingLength);
-
- try
- {
- bool success = NativeMethods.QueryInformationJobObject(this.jobHandle, NativeMethods.JobObjectInfoClass.JobObjectBasicAndIoAccountingInformation, accountingPtr, (uint)accountingLength, IntPtr.Zero);
-
- if (success == false)
- {
- int error = Marshal.GetLastWin32Error();
- throw new Win32Exception(error, "QueryInformationJobObject failed.");
- }
-
- accounting = (NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION)Marshal.PtrToStructure(accountingPtr, typeof(NativeMethods.JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION));
-
- this.userProcessorTime = (ulong)accounting.BasicInfo.TotalUserTime;
- this.kernelProcessorTime = (ulong)accounting.BasicInfo.TotalKernelTime;
-
- this.ioReadBytes = (long)accounting.IoInfo.ReadTransferCount;
- this.ioWriteBytes = (long)accounting.IoInfo.WriteTransferCount;
- this.ioOtherBytes = (long)accounting.IoInfo.OtherTransferCount;
- this.ioReadOperationsCount = (long)accounting.IoInfo.ReadOperationCount;
- this.ioWriteOperationsCount = (long)accounting.IoInfo.WriteOperationCount;
- this.ioOtherOperationsCount = (long)accounting.IoInfo.OtherOperationCount;
- }
- finally
- {
- Marshal.FreeHGlobal(accountingPtr);
- }
- }
-
- /// <summary>
- /// Queries the extended limit information.
- /// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "QueryInformationJobObject", Justification = "Spelling is correct.")]
- private void QueryExtendedLimitInformation()
- {
- NativeMethods.JOBOBJECT_EXTENDED_LIMIT_INFORMATION extendedLimit;
-
- int extenedLimitLength = Marshal.SizeOf(typeof(NativeMethods.JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
- IntPtr extendedLimitPtr = Marshal.AllocHGlobal(extenedLimitLength);
-
- try
- {
- bool success = NativeMethods.QueryInformationJobObject(this.jobHandle, NativeMethods.JobObjectInfoClass.JobObjectExtendedLimitInformation, extendedLimitPtr, (uint)extenedLimitLength, IntPtr.Zero);
-
- if (success == false)
- {
- int error = Marshal.GetLastWin32Error();
- throw new Win32Exception(error, "QueryInformationJobObject failed.");
- }
-
- extendedLimit = (NativeMethods.JOBOBJECT_EXTENDED_LIMIT_INFORMATION)Marshal.PtrToStructure(extendedLimitPtr, typeof(NativeMethods.JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
-
- this.peakJobMemory = (ulong)extendedLimit.PeakJobMemoryUsed;
- this.peakProcessMemory = (ulong)extendedLimit.PeakProcessMemoryUsed;
- }
- finally
- {
- Marshal.FreeHGlobal(extendedLimitPtr);
- }
- }
- }
-}
View
40 src/IronFoundry.Dea/WindowsJobObjects/JobObjectHandle.cs
@@ -1,40 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) 2011 Uhuru Software, Inc., All Rights Reserved
-// Copyright (c) 2012 Tier 3, Inc.
-// THE CONTENTS OF THE ORIGINAL FILE HAVE BEEN MODIFIED BY TIER 3
-// -----------------------------------------------------------------------
-
-namespace IronFoundry.Dea.WindowsJobObjects
-{
- using System.Runtime.ConstrainedExecution;
- using System.Security.Permissions;
- using Microsoft.Win32.SafeHandles;
-
- /// <summary>
- /// A safe handle for Job Object.
- /// </summary>
- [SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
- [SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
- internal class JobObjectHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- /// <summary>
- /// Prevents a default instance of the <see cref="JobObjectHandle"/> class from being created.
- /// </summary>
- private JobObjectHandle()
- : base(true)
- {
- }
-
- /// <summary>
- /// When overridden in a derived class, executes the code required to free the handle.
- /// </summary>
- /// <returns>
- /// true if the handle is released successfully; otherwise, in the event of a catastrophic failure, false. In this case, it generates a releaseHandleFailed MDA Managed Debugging Assistant.
- /// </returns>
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- protected override bool ReleaseHandle()
- {
- return NativeMethods.CloseHandle(handle);
- }
- }
-}
View
443 src/IronFoundry.Dea/WindowsJobObjects/NativeMethods.cs
@@ -1,443 +0,0 @@
-// -----------------------------------------------------------------------
-// Copyright (c) 2011 Uhuru Software, Inc., All Rights Reserved
-// Copyright (c) 2012 Tier 3, Inc.
-// THE CONTENTS OF THE ORIGINAL FILE HAVE BEEN MODIFIED BY TIER 3
-// -----------------------------------------------------------------------
-
-namespace IronFoundry.Dea.WindowsJobObjects
-{
- using System;
- using System.Diagnostics.CodeAnalysis;
- using System.Runtime.InteropServices;
- using System.Security;
-
- /// <summary>
- /// Job Objects Windows API native methods.
- /// </summary>
- [SuppressUnmanagedCodeSecurity]
- internal static class NativeMethods
- {
- /// <summary>
- /// Used for calling the Win API
- /// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1027:MarkEnumsWithFlags", Justification = "Appropriate to suppress.")]
- internal enum JobObjectInfoClass
- {
- /// <summary>
- /// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_ACCOUNTING_INFORMATION structure.
- /// </summary>
- JobObjectBasicAccountingInformation = 1,
-
- /// <summary>
- /// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION structure.
- /// </summary>
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Io", Justification = "Appropriate to suppress.")]
- JobObjectBasicAndIoAccountingInformation = 8,
-
- /// <summary>
- /// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
- /// </summary>
- JobObjectBasicLimitInformation = 2,
-
- /// <summary>
- /// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_PROCESS_ID_LIST structure.
- /// </summary>
- JobObjectBasicProcessIdList = 3,
-
- /// <summary>
- /// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_UI_RESTRICTIONS structure.
- /// </summary>
- JobObjectBasicUIRestrictions = 4,
-
- /// <summary>
- /// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_END_OF_JOB_TIME_INFORMATION structure.
- /// </summary>
- JobObjectEndOfJobTimeInformation = 6,
-
- /// <summary>
- /// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure.
- /// </summary>
- JobObjectExtendedLimitInformation = 9,
-
- /// <summary>
- /// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_ASSOCIATE_COMPLETION_PORT structure.
- /// </summary>
- JobObjectAssociateCompletionPortInformation = 7,
- }
-
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
- public static extern JobObjectHandle CreateJobObject(IntPtr lpJobAttributes, string lpName);
-
- [DllImport("kernel32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool IsProcessInJob(IntPtr Process, JobObjectHandle hJob, [MarshalAs(UnmanagedType.Bool)] out bool Result);
-
- [DllImport("kernel32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool SetInformationJobObject(JobObjectHandle hJob, JobObjectInfoClass JobObjectInfoClass, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength);
-
- [DllImport("kernel32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool QueryInformationJobObject(JobObjectHandle hJob, JobObjectInfoClass JobObjectInformationClass, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength, IntPtr lpReturnLength);
-
- [DllImport("kernel32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool AssignProcessToJobObject(JobObjectHandle hJob, IntPtr hProcess);
-
- [DllImport("kernel32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool TerminateJobObject(JobObjectHandle hJob, uint uExitCode);
-
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
- public static extern JobObjectHandle OpenJobObject(uint dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, string lpName);
-
- [DllImport("kernel32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool CloseHandle(IntPtr hHandle);
-
- /// <summary>
- /// The SECURITY_ATTRIBUTES structure contains the security descriptor for an object and specifies whether the handle retrieved by specifying this structure is inheritable.
- /// </summary>
- [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Preserve WinAPI naming.")]
- [StructLayout(LayoutKind.Sequential)]
- internal struct SECURITY_ATTRIBUTES
- {
- /// <summary>
- /// Length of the structure.
- /// </summary>
- public int Length;
-
- /// <summary>
- /// Security Descriptor
- /// </summary>
- public IntPtr SecurityDescriptor;
-
- /// <summary>
- /// Child process inheritance.
- /// </summary>
- public int InheritHandle;
- }
-
- /// <summary>
- /// Contains basic and extended limit information for a job object.
- /// </summary>
- [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:FieldNamesMustNotContainUnderscore", Justification = "Preserve WinAPI naming.")]
- [StructLayout(LayoutKind.Sequential)]
- internal struct JOBOBJECT_BASIC_LIMIT_INFORMATION
- {
- /// <summary>
- /// JOB_OBJECT_LIMIT_ACTIVE_PROCESS Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_ACTIVE_PROCESS = 0x00000008;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_AFFINITY Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_AFFINITY = 0x00000010;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_BREAKAWAY_OK Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_BREAKAWAY_OK = 0x00000800;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION = 0x00000400;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_JOB_MEMORY Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_JOB_MEMORY = 0x00000200;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_JOB_TIME Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_JOB_TIME = 0x00000004;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE = 0x00002000;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME = 0x00000040;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_PRIORITY_CLASS Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_PRIORITY_CLASS = 0x00000020;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_PROCESS_MEMORY Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_PROCESS_TIME Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_PROCESS_TIME = 0x00000002;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_SCHEDULING_CLASS Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_SCHEDULING_CLASS = 0x00000080;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK = 0x00001000;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_SUBSET_AFFINITY = 0x00004000;
-
- /// <summary>
- /// JOB_OBJECT_LIMIT_WORKINGSET Windows API constant.
- /// </summary>
- public const uint JOB_OBJECT_LIMIT_WORKINGSET = 0x00000001;
-
- /// <summary>
- /// Per process user time limit.
- /// </summary>
- public long PerProcessUserTimeLimit;
-
- /// <summary>
- /// Per job user time limit.
- /// </summary>
- public long PerJobUserTimeLimit;
-
- /// <summary>
- /// Limit flags.
- /// </summary>
- public uint LimitFlags;
-
- /// <summary>
- /// Minimum working set size.
- /// </summary>
- public IntPtr MinimumWorkingSetSize;
-
- /// <summary>
- /// Maximum working set size.
- /// </summary>
- public IntPtr MaximumWorkingSetSize;
-
- /// <summary>
- /// Active process limit.
- /// </summary>
- public uint ActiveProcessLimit;
-
- /// <summary>
- /// Processor affinity.
- /// </summary>
- public IntPtr Affinity;
-
- /// <summary>
- /// Priority class.
- /// </summary>
- public uint PriorityClass;
-
- /// <summary>
- /// Scheduling class.
- /// </summary>
- public uint SchedulingClass;
- }
-
- /// <summary>
- /// JOBOBJECT_BASIC_UI_RESTRICTIONS Windows API structure.
- /// </summary>
- [StructLayout(LayoutKind.Sequential)]
- internal struct JOBOBJECT_BASIC_UI_RESTRICTIONS
- {
- /// <summary>
- /// UI Restrictions class.
- /// </summary>
- public uint UIRestrictionsClass;
- }
-
- /// <summary>
- /// JOBOBJECT_CPU_RATE_CONTROL_INFORMATION Windows API structure.
- /// </summary>
- [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:FieldNamesMustNotContainUnderscore", Justification = "Preserve WinAPI naming.")]
- [StructLayout(LayoutKind.Sequential)]
- internal struct JOBOBJECT_CPU_RATE_CONTROL_INFORMATION
- {
- /// <summary>
- /// Control Flags.
- /// </summary>
- public uint ControlFlags;
-
- /// <summary>
- /// CPU rate weight.
- /// </summary>
- public uint CpuRate_Weight;
- }
-
- /// <summary>
- /// JOBOBJECT_EXTENDED_LIMIT_INFORMATION Windows API structure.
- /// </summary>
- [StructLayout(LayoutKind.Sequential)]
- internal struct JOBOBJECT_EXTENDED_LIMIT_INFORMATION
- {
- /// <summary>
- /// BasicLimitInformation Windows API structure member.
- /// </summary>
- public JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation;
-
- /// <summary>
- /// IoInfo Windows API structure member.
- /// </summary>
- public IO_COUNTERS IoInfo;
-
- /// <summary>
- /// ProcessMemoryLimit Windows API structure member.
- /// </summary>
- public IntPtr ProcessMemoryLimit;
-
- /// <summary>
- /// JobMemoryLimit Windows API structure member.
- /// </summary>
- public IntPtr JobMemoryLimit;
-
- /// <summary>
- /// PeakProcessMemoryUsed Windows API structure member.
- /// </summary>
- public IntPtr PeakProcessMemoryUsed;
-
- /// <summary>
- /// PeakJobMemoryUsed Windows API structure member.
- /// </summary>
- public IntPtr PeakJobMemoryUsed;
- }
-
- /// <summary>
- /// IO_COUNTERS Windows API structure.
- /// </summary>
- [StructLayout(LayoutKind.Sequential)]
- internal struct IO_COUNTERS
- {
- /// <summary>
- /// ReadOperationCount Windows API structure member.
- /// </summary>
- public ulong ReadOperationCount;
-
- /// <summary>
- /// WriteOperationCount Windows API structure member.
- /// </summary>
- public ulong WriteOperationCount;
-
- /// <summary>
- /// OtherOperationCount Windows API structure member.
- /// </summary>
- public ulong OtherOperationCount;
-
- /// <summary>
- /// ReadTransferCount Windows API structure member.
- /// </summary>
- public ulong ReadTransferCount;
-
- /// <summary>
- /// WriteTransferCount Windows API structure member.
- /// </summary>
- public ulong WriteTransferCount;
-
- /// <summary>
- /// OtherTransferCount Windows API structure member.
- /// </summary>
- public ulong OtherTransferCount;
- }
-
- /// <summary>
- /// JOBOBJECT_BASIC_ACCOUNTING_INFORMATION Windows API structure.
- /// </summary>
- [StructLayout(LayoutKind.Sequential)]
- internal struct JOBOBJECT_BASIC_ACCOUNTING_INFORMATION
- {
- /// <summary>
- /// TotalUserTime Windows API structure member.
- /// </summary>
- public ulong TotalUserTime;
-
- /// <summary>
- /// TotalKernelTime Windows API structure member.
- /// </summary>
- public ulong TotalKernelTime;
-
- /// <summary>
- /// ThisPeriodTotalUserTime Windows API structure member.
- /// </summary>
- public ulong ThisPeriodTotalUserTime;
-
- /// <summary>
- /// ThisPeriodTotalKernelTime Windows API structure member.
- /// </summary>
- public ulong ThisPeriodTotalKernelTime;
-
- /// <summary>
- /// TotalPageFaultCount Windows API structure member.
- /// </summary>
- public uint TotalPageFaultCount;
-
- /// <summary>
- /// TotalProcesses Windows API structure member.
- /// </summary>
- public uint TotalProcesses;
-
- /// <summary>
- /// ActiveProcesses Windows API structure member.
- /// </summary>
- public uint ActiveProcesses;
-
- /// <summary>
- /// TotalTerminatedProcesses Windows API structure member.
- /// </summary>
- public uint TotalTerminatedProcesses;
- }
-
- /// <summary>
- /// JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION Windows API structure.
- /// </summary>
- internal struct JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION
- {
- /// <summary>
- /// BasicInfo Windows API structure member.
- /// </summary>
- public JOBOBJECT_BASIC_ACCOUNTING_INFORMATION BasicInfo;
-
- /// <summary>
- /// IoInfo Windows API structure member.
- /// </summary>
- public IO_COUNTERS IoInfo;
- }
-
- /// <summary>
- /// JOBOBJECT_BASIC_PROCESS_ID_LIST Windows API structure.
- /// </summary>
- internal struct JOBOBJECT_BASIC_PROCESS_ID_LIST
- {
- /// <summary>
- /// The maximum number of processes that are allocated when querying Windows API.
- /// </summary>
- public const uint MaxProcessListLength = 200;
-
- /// <summary>
- /// NumberOfAssignedProcesses Windows API structure member.
- /// </summary>
- public uint NumberOfAssignedProcesses;
-
- /// <summary>
- /// NumberOfProcessIdsInList Windows API structure member.
- /// </summary>
- public uint NumberOfProcessIdsInList;
-
- /// <summary>
- /// ProcessIdList Windows API structure member.
- /// </summary>
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)MaxProcessListLength)]
- public IntPtr[] ProcessIdList;
- }
- }
-}
Please sign in to comment.
Something went wrong with that request. Please try again.