/// <summary> /// Creates a new <see cref="JobObject"/> instance. /// </summary> /// <param name="Limits">The <see cref="JobLimits"/> to apply to the new <see cref="JobObject"/>.</param> /// <param name="Notifications">The <see cref="JobNotifications"/> to apply to the new <see cref="JobObject"/>.</param> public JobObject(JobLimits?Limits = null, JobNotifications?Notifications = null) { try { // get the completion port reference.. _completionPort = JobObjectCompletionPort.GetCompletionPort(); // create the handle.. _handle = Interop.Kernel32.CreateJobObject(IntPtr.Zero, null); if ((_handle == null) || (_handle.IsInvalid)) { throw Errors.Win32Error(); } // join the handle to the completion port.. AssociateWithPort(); // configure limits.. if (Limits.HasValue) { SetLimits(Limits.Value); } if ((Notifications.HasValue) && (_jobsLimitViolationSupported)) { SetNotifications(Notifications.Value); } } catch { Dispose(); throw; } }
internal static extern bool DuplicateHandle( IntPtr hSourceProcessHandle, SafeJobObjectHandle hSourceHandle, IntPtr hTargetProcess, out SafeJobObjectHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions );
static JobObjectInfo() { // create a JobObject and determine what options are supported on this OS.. SafeJobObjectHandle jobHandle = null; try { jobHandle = Interop.Kernel32.CreateJobObject(IntPtr.Zero, null); if (jobHandle.IsInvalid) { return; } _jobsSupported = true; // notification limit // notification limit 2 // net rate control // violation limit // violation limit 2 // job object group info // cpu rate control // group information ex IntPtr memoryPtr = IntPtr.Zero; try { int memorySize = 1024; memoryPtr = Marshal.AllocHGlobal(memorySize); // ask for specific structures to determine the level of support.. _jobsGroupSupported = IsSupported(jobHandle, Interop.Kernel32.JobObjectInformationClass.GroupInformation, memoryPtr, memorySize); _jobsGroupExSupported = IsSupported(jobHandle, Interop.Kernel32.JobObjectInformationClass.GroupInformationEx, memoryPtr, memorySize); _jobsLimitViolationSupported = IsSupported(jobHandle, Interop.Kernel32.JobObjectInformationClass.LimitViolationInformation, memoryPtr, memorySize); _jobsLimitViolation2Supported = IsSupported(jobHandle, Interop.Kernel32.JobObjectInformationClass.LimitViolationInformation2, memoryPtr, memorySize); } finally { if (memoryPtr != IntPtr.Zero) { Marshal.FreeHGlobal(memoryPtr); } } } finally { jobHandle?.Dispose(); } }
public WindowsChildProcessState( int processId, SafeProcessHandle processHandle, SafeJobObjectHandle jobObjectHandle, InputWriterOnlyPseudoConsole?pseudoConsole, bool allowSignal) { Debug.Assert(!(allowSignal && pseudoConsole is null)); _processId = processId; _processHandle = processHandle; _jobObjectHandle = jobObjectHandle; _pseudoConsole = pseudoConsole; _allowSignal = allowSignal; _exitedWaitHandle = new WindowsProcessWaitHandle(_processHandle); }
internal static extern bool QueryInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, IntPtr lpJobObjectInfo, int cbJobObjectInfoLength, out int lpReturnLength);
internal static extern bool QueryInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [Out] out JOBOBJECT_LIMIT_VIOLATION_INFORMATION lpJobObjectInfo, int cbJobObjectInfoLength, IntPtr lpReturnLength);
internal static extern bool QueryInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [Out] out JOBOBJECT_BASIC_UI_RESTRICTIONS lpJobObjectInfo, int cbJobObjectInfoLength, IntPtr lpReturnLength);
internal static extern bool QueryInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [Out] out JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION lpJobObjectInfo, int cbJobObjectInfoLength, IntPtr lpReturnLength);
internal static extern bool SetInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [In] ref JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION lpJobObjectInfo, int cbJobObjectInfoLength);
internal static extern bool SetInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [In] ref JOBOBJECT_CPU_RATE_CONTROL_INFORMATION lpJobObjectInfo, int cbJobObjectInfoLength);
public unsafe JobObject(string name = null) { mHandle = Kernel32.CreateJobObjectW(null, name); }
internal static extern bool SetInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [In] ref JOBOBJECT_END_OF_JOB_TIME_INFORMATION lpJobObjectInfo, int cbJobObjectInfoLength);
internal static extern bool SetInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [In] ref JOBOBJECT_ASSOCIATE_COMPLETION_PORT lpJobObjectInfo, int cbJobObjectInfoLength);
internal static extern bool AssignProcessToJobObject(SafeJobObjectHandle hJob, SafeProcessHandle hProcess);
internal static extern bool SetInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [In] ref JOBOBJECT_BASIC_UI_RESTRICTIONS lpJobObjectInfo, int cbJobObjectInfoLength);
internal static extern bool TerminateJobObject(SafeJobObjectHandle hJob, int uExitCode);
internal static extern bool UserHandleGrantAccess(IntPtr hUserHandle, SafeJobObjectHandle hJob, BOOL bGrant);