using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
namespace Vanara.PInvoke
{
public static partial class Kernel32
{
///
public const int JOB_OBJECT_NET_RATE_CONTROL_MAX_DSCP_TAG = 64;
/// The scheduling policy for CPU rate control.
[Flags]
public enum JOB_OBJECT_CPU_RATE_CONTROL_FLAGS
{
///
/// This flag enables the job's CPU rate to be controlled based on weight or hard cap. You must set this value if you also set
/// JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED, JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP, or JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE.
///
JOB_OBJECT_CPU_RATE_CONTROL_ENABLE = 0x1,
///
/// The job's CPU rate is calculated based on its relative weight to the weight of other jobs. If this flag is set, the Weight
/// member contains more information. If this flag is clear, the CpuRate member contains more information.If you set
/// JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED, you cannot also set JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE.
///
JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED = 0x2,
///
/// The job's CPU rate is a hard limit. After the job reaches its CPU cycle limit for the current scheduling interval, no threads
/// associated with the job will run until the next interval. If you set JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP, you cannot also
/// set JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE.
///
JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP = 0x4,
/// Sends messages when the CPU rate for the job exceeds the rate limits for the job during the tolerance interval.
JOB_OBJECT_CPU_RATE_CONTROL_NOTIFY = 0x8,
///
/// The CPU rate for the job is limited by minimum and maximum rates that you specify in the MinRate and MaxRate members.If you
/// set JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE, you can set neither JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED nor JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP.
///
JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE = 0x10,
}
/// The policy for control of the I/O rate.
[Flags]
public enum JOB_OBJECT_IO_RATE_CONTROL_FLAGS
{
///
/// Turns on control of the I/O rate for the job when this structure is passed to the SetIoRateControlInformationJobObject
/// function. Indicates that control of the I/O rate for the job is turned on when this structure is used with the
/// QueryIoRateControlInformationJobObject function.
///
JOB_OBJECT_IO_RATE_CONTROL_ENABLE = 0x1,
///
JOB_OBJECT_IO_RATE_CONTROL_STANDALONE_VOLUME = 0x2,
///
JOB_OBJECT_IO_RATE_CONTROL_FORCE_UNIT_ACCESS_ALL = 0x4,
///
JOB_OBJECT_IO_RATE_CONTROL_FORCE_UNIT_ACCESS_ON_SOFT_CAP = 0x8,
}
///
/// Completion Port Messages for job objects. These values are returned via the lpNumberOfBytesTransferred parameter when calling GetQueuedCompletionStatus.
///
[Flags]
public enum JOB_OBJECT_MSG : uint
{
///
/// Indicates that the JOB_OBJECT_POST_AT_END_OF_JOB option is in effect and the end-of-job time limit has been reached. Upon
/// posting this message, the time limit is canceled and the job's processes can continue to run. The value of lpOverlapped is NULL.
///
JOB_OBJECT_MSG_END_OF_JOB_TIME = 1,
///
/// Indicates that a process has exceeded a per-process time limit. The system sends this message after the process termination
/// has been requested. The value of lpOverlapped is the identifier of the process that exceeded its limit.
///
JOB_OBJECT_MSG_END_OF_PROCESS_TIME = 2,
/// Indicates that the active process limit has been exceeded. The value of lpOverlapped is NULL.
JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT = 3,
///
/// Indicates that the active process count has been decremented to 0. For example, if the job currently has two active
/// processes, the system sends this message after they both terminate. The value of lpOverlapped is NULL.
///
JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO = 4,
///
/// Indicates that a process has been added to the job. Processes added to a job at the time a completion port is associated are
/// also reported. The value of lpOverlapped is the identifier of the process added to the job.
///
JOB_OBJECT_MSG_NEW_PROCESS = 6,
///
/// Indicates that a process associated with the job has exited. The value of lpOverlapped is the identifier of the exiting process.
///
JOB_OBJECT_MSG_EXIT_PROCESS = 7,
///
/// Indicates that a process associated with the job exited with an exit code that indicates an abnormal exit (see the list
/// following this table). The value of lpOverlapped is the identifier of the exiting process.
///
JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS = 8,
///
/// Indicates that a process associated with the job has exceeded its memory limit (if one is in effect). The value of
/// lpOverlapped is the identifier of the process that has exceeded its limit. The system does not send this message if the
/// process has not yet reported its process identifier.
///
JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT = 9,
///
/// Indicates that a process associated with the job caused the job to exceed the job-wide memory limit (if one is in effect).
/// The value of lpOverlapped specifies the identifier of the process that has attempted to exceed the limit. The system does not
/// send this message if the process has not yet reported its process identifier.
///
JOB_OBJECT_MSG_JOB_MEMORY_LIMIT = 10,
///
/// Indicates that a process associated with a job that has registered for resource limit notifications has exceeded one or more
/// limits. Use the QueryInformationJobObject function with JobObjectLimitViolationInformation to determine which limit was
/// exceeded. The value of lpOverlapped is the identifier of the process that has exceeded its limit. The system does not send
/// this message if the process has not yet reported its process identifier.
///
JOB_OBJECT_MSG_NOTIFICATION_LIMIT = 11,
/// Undocumented.
JOB_OBJECT_MSG_JOB_CYCLE_TIME_LIMIT = 12,
/// Undocumented.
JOB_OBJECT_MSG_SILO_TERMINATED = 13,
}
/// Specifies types of scheduling policies for network rate control.
// typedef enum JOB_OBJECT_NET_RATE_CONTROL_FLAGS { JOB_OBJECT_NET_RATE_CONTROL_ENABLE = 0x1,
// JOB_OBJECT_NET_RATE_CONTROL_MAX_BANDWITH = 0x2, JOB_OBJECT_NET_RATE_CONTROL_DSCP_TAG = 0x4,
// JOB_OBJECT_NET_RATE_CONTROL_VALID_FLAGS = 0x7} JOB_OBJECT_NET_RATE_CONTROL_FLAGS; https://msdn.microsoft.com/en-us/library/windows/desktop/mt280126(v=vs.85).aspx
[PInvokeData("Winnt.h", MSDNShortId = "mt280126")]
[Flags]
public enum JOB_OBJECT_NET_RATE_CONTROL_FLAGS
{
///
/// Turns on the control of the network traffic. You must set this value if you also set either
/// JOB_OBJECT_NET_RATE_CONTROL_MAX_BANDWIDTH or JOB_OBJECT_NET_RATE_CONTROL_DSCP_TAG.
///
JOB_OBJECT_NET_RATE_CONTROL_ENABLE = 0x1,
///
/// Uses the value of the MaxBandwidth member of the JOBOBJECT_NET_RATE_CONTROL_INFORMATION structure to set the
/// maximum bandwidth for outgoing network traffic for the job, in bytes.
///
JOB_OBJECT_NET_RATE_CONTROL_MAX_BANDWIDTH = 0x2,
///
/// Sets the DSCP field in the packet header to the value of the DscpTag member of the
/// JOBOBJECT_NET_RATE_CONTROL_INFORMATION structure. For information about DSCP, see Differentiated Services.
///
JOB_OBJECT_NET_RATE_CONTROL_DSCP_TAG = 0x4,
/// The combination of all of the valid flags for the JOB_OBJECT_NET_RATE_CONTROL_FLAGS enumeration.
JOB_OBJECT_NET_RATE_CONTROL_VALID_FLAGS = 0x7
}
///
///
/// The Microsoft Windows security model enables you to control access to job objects. For more information about security, see
/// Access-Control Model.
///
///
/// You can specify a security descriptor for a job object when you call the CreateJobObject function. If you specify NULL,
/// the job object gets a default security descriptor. The ACLs in the default security descriptor for a job object come from the
/// primary or impersonation token of the creator.
///
///
/// To get or set the security descriptor for a job object, call the GetNamedSecurityInfo, SetNamedSecurityInfo,
/// GetSecurityInfo, or SetSecurityInfo function.
///
///
/// The valid access rights for job objects include the standard access rights and some job-specific access rights. The following
/// table lists the standard access rights used by all objects.
///
///
///
/// Value
/// Meaning
///
/// -
/// DELETE (0x00010000L)
/// Required to delete the object.
///
/// -
/// READ_CONTROL (0x00020000L)
///
/// Required to read information in the security descriptor for the object, not including the information in the SACL. To read or
/// write the SACL, you must request the ACCESS_SYSTEM_SECURITY access right. For more information, see SACL Access Right.
///
///
/// -
/// SYNCHRONIZE (0x00100000L)
/// The right to use the object for synchronization. This enables a thread to wait until the object is in the signaled state.
///
/// -
/// WRITE_DAC (0x00040000L)
/// Required to modify the DACL in the security descriptor for the object.
///
/// -
/// WRITE_OWNER (0x00080000L)
/// Required to change the owner in the security descriptor for the object.
///
///
/// The following table lists the job-specific access rights.
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_ALL_ACCESS (0x1F001F)
/// Combines all valid job object access rights.
///
/// -
/// JOB_OBJECT_ASSIGN_PROCESS (0x0001)
/// Required to call the AssignProcessToJobObject function to assign processes to the job object.
///
/// -
/// JOB_OBJECT_QUERY (0x0004)
///
/// Required to retrieve certain information about a job object, such as attributes and accounting information (see
/// QueryInformationJobObject and IsProcessInJob).
///
///
/// -
/// JOB_OBJECT_SET_ATTRIBUTES (0x0002)
/// Required to call the SetInformationJobObject function to set the attributes of the job object.
///
/// -
/// JOB_OBJECT_SET_SECURITY_ATTRIBUTES (0x0010)
///
/// This flag is not supported. You must set security limitations individually for each process associated with a job object.Windows
/// Server 2003 and Windows XP: Required to call the SetInformationJobObject function with the JobObjectSecurityLimitInformation
/// information class to set security limitations for the processes associated with the job object. Support for this flag was removed
/// in Windows Vista and Windows Server 2008.
///
///
/// -
/// JOB_OBJECT_TERMINATE (0x0008)
/// Required to call the TerminateJobObject function to terminate all processes in the job object.
///
///
///
/// The handle returned by CreateJobObject has JOB_OBJECT_ALL_ACCESS access to the job object. When you call the
/// OpenJobObject function, the system checks the requested access rights against the object's security descriptor. If a job
/// object is in a hierarchy of nested jobs, a caller with access to the job object implicitly has access to all of its child jobs in
/// the hierarchy.
///
///
/// You can request the ACCESS_SYSTEM_SECURITY access right to a job object if you want to read or write the object's SACL.
/// For more information, see Access-Control Lists (ACLs) and SACL Access Right.
///
///
/// You must set security limitations individually for each process associated with a job object, rather than setting them for the
/// job object itself. For information, see Process Security and Access Rights.
///
///
/// **Windows Server 2003 and Windows XP: ** You can use the SetInformationJobObject function to set security limitations for
/// the job object. This capability was removed in Windows Vista and Windows Server 2008.
///
///
// https://docs.microsoft.com/en-us/windows/win32/procthread/job-object-security-and-access-rights
[PInvokeData("", MSDNShortId = "8d212292-f087-41e4-884e-cec4423dac49")]
[Flags]
public enum JobAccessRight : uint
{
/// Required to delete the object.
DELETE = ACCESS_MASK.DELETE,
///
/// Required to read information in the security descriptor for the object, not including the information in the SACL. To read or
/// write the SACL, you must request the ACCESS_SYSTEM_SECURITY access right. For more information, see SACL Access Right.
///
READ_CONTROL = ACCESS_MASK.READ_CONTROL,
///
/// The right to use the object for synchronization. This enables a thread to wait until the object is in the signaled state.
///
SYNCHRONIZE = ACCESS_MASK.SYNCHRONIZE,
/// Required to modify the DACL in the security descriptor for the object.
WRITE_DAC = ACCESS_MASK.WRITE_DAC,
/// Required to change the owner in the security descriptor for the object.
WRITE_OWNER = ACCESS_MASK.WRITE_OWNER,
/// Required to call the AssignProcessToJobObject function to assign processes to the job object.
JOB_OBJECT_ASSIGN_PROCESS = 0x0001,
///
/// Required to retrieve certain information about a job object, such as attributes and accounting information (see
/// QueryInformationJobObject and IsProcessInJob).
///
JOB_OBJECT_QUERY = 0x0004,
/// Required to call the SetInformationJobObject function to set the attributes of the job object.
JOB_OBJECT_SET_ATTRIBUTES = 0x0002,
///
/// This flag is not supported. You must set security limitations individually for each process associated with a job
/// object.Windows Server 2003 and Windows XP: Required to call the SetInformationJobObject function with the
/// JobObjectSecurityLimitInformation information class to set security limitations for the processes associated with the job
/// object. Support for this flag was removed in Windows Vista and Windows Server 2008.
///
JOB_OBJECT_SET_SECURITY_ATTRIBUTES = 0x0010,
/// Required to call the TerminateJobObject function to terminate all processes in the job object.
JOB_OBJECT_TERMINATE = 0x0008,
/// Undocumented.
JOB_OBJECT_IMPERSONATE = 0x0020,
/// Combines all valid job object access rights.
JOB_OBJECT_ALL_ACCESS = ACCESS_MASK.STANDARD_RIGHTS_REQUIRED | ACCESS_MASK.SYNCHRONIZE | 0x3F,
}
/// The action that the system will perform when the end-of-job time limit has been exceeded.
public enum JOBOBJECT_END_OF_JOB_TIME_ACTION
{
///
/// Terminates all processes and sets the exit status to ERROR_NOT_ENOUGH_QUOTA. The processes cannot prevent or delay their own
/// termination. The job object is set to the signaled state and remains signaled until this limit is reset. No additional
/// processes can be assigned to the job until the limit is reset. This is the default termination action.
///
JOB_OBJECT_TERMINATE_AT_END_OF_JOB = 0,
///
/// Posts a completion packet to the completion port using the PostQueuedCompletionStatus function. After the completion packet
/// is posted, the system clears the end-of-job time limit, and processes in the job can continue their execution. If no
/// completion port is associated with the job when the time limit has been exceeded, the action taken is the same as for JOB_OBJECT_TERMINATE_AT_END_OF_JOB.
///
JOB_OBJECT_POST_AT_END_OF_JOB = 1
}
///
[Flags]
public enum JOBOBJECT_IO_ATTRIBUTION_CONTROL_FLAGS
{
///
JOBOBJECT_IO_ATTRIBUTION_CONTROL_ENABLE = 0x1,
///
JOBOBJECT_IO_ATTRIBUTION_CONTROL_DISABLE = 0x2,
///
JOBOBJECT_IO_ATTRIBUTION_CONTROL_VALID_FLAGS = 0x3
}
/// Flags that identify the notification limits in effect for the job.
[Flags]
public enum JOBOBJECT_LIMIT_FLAGS
{
///
/// Causes all processes associated with the job to use the same minimum and maximum working set sizes. The MinimumWorkingSetSize
/// and MaximumWorkingSetSize members contain additional information.If the job is nested, the effective working set size is the
/// smallest working set size in the job chain.
///
JOB_OBJECT_LIMIT_WORKINGSET = 0x00000001,
///
/// Establishes a user-mode execution time limit for each currently active process and for all future processes associated with
/// the job. The PerProcessUserTimeLimit member contains additional information.
///
JOB_OBJECT_LIMIT_PROCESS_TIME = 0x00000002,
///
/// Establishes a user-mode execution time limit for the job. The PerJobUserTimeLimit member contains additional information.
/// This flag cannot be used with JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME.
///
JOB_OBJECT_LIMIT_JOB_TIME = 0x00000004,
///
/// Establishes a maximum number of simultaneously active processes associated with the job. The ActiveProcessLimit member
/// contains additional information.
///
JOB_OBJECT_LIMIT_ACTIVE_PROCESS = 0x00000008,
///
/// Causes all processes associated with the job to use the same processor affinity. The Affinity member contains additional
/// information.If the job is nested, the specified processor affinity must be a subset of the effective affinity of the parent
/// job. If the specified affinity a superset of the affinity of the parent job, it is ignored and the affinity of the parent job
/// is used.
///
JOB_OBJECT_LIMIT_AFFINITY = 0x00000010,
///
/// Causes all processes associated with the job to use the same priority class. For more information, see Scheduling Priorities.
/// The PriorityClass member contains additional information.If the job is nested, the effective priority class is the lowest
/// priority class in the job chain.
///
JOB_OBJECT_LIMIT_PRIORITY_CLASS = 0x00000020,
///
/// Preserves any job time limits you previously set. As long as this flag is set, you can establish a per-job time limit once,
/// then alter other limits in subsequent calls. This flag cannot be used with JOB_OBJECT_LIMIT_JOB_TIME.
///
JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME = 0x00000040,
///
/// Causes all processes in the job to use the same scheduling class. The SchedulingClass member contains additional
/// information.If the job is nested, the effective scheduling class is the lowest scheduling class in the job chain.
///
JOB_OBJECT_LIMIT_SCHEDULING_CLASS = 0x00000080,
///
/// Causes all processes associated with the job to limit their committed memory. When a process attempts to commit memory that
/// would exceed the per-process limit, it fails. If the job object is associated with a completion port, a
/// JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT message is sent to the completion port.If the job is nested, the effective memory limit
/// is the most restrictive memory limit in the job chain.This limit requires use of a JOBOBJECT_EXTENDED_LIMIT_INFORMATION
/// structure. Its BasicLimitInformation member is a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100,
///
/// Causes all processes associated with the job to limit the job-wide sum of their committed memory. When a process attempts to
/// commit memory that would exceed the job-wide limit, it fails. If the job object is associated with a completion port, a
/// JOB_OBJECT_MSG_JOB_MEMORY_LIMIT message is sent to the completion port.This limit requires use of a
/// JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure. Its BasicLimitInformation member is a JOBOBJECT_BASIC_LIMIT_INFORMATION
/// structure.To register for notification when this limit is exceeded while allowing processes to continue to commit memory, use
/// the SetInformationJobObject function with the JobObjectNotificationLimitInformation information class.
///
JOB_OBJECT_LIMIT_JOB_MEMORY = 0x00000200,
///
/// Forces a call to the SetErrorMode function with the SEM_NOGPFAULTERRORBOX flag for each process associated with the job. If
/// an exception occurs and the system calls the UnhandledExceptionFilter function, the debugger will be given a chance to act.
/// If there is no debugger, the functions returns EXCEPTION_EXECUTE_HANDLER. Normally, this will cause termination of the
/// process with the exception code as the exit status.This limit requires use of a JOBOBJECT_EXTENDED_LIMIT_INFORMATION
/// structure. Its BasicLimitInformation member is a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION = 0x00000400,
///
/// If any process associated with the job creates a child process using the CREATE_BREAKAWAY_FROM_JOB flag while this limit is
/// in effect, the child process is not associated with the job. This limit requires use of a
/// JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure. Its BasicLimitInformation member is a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
JOB_OBJECT_LIMIT_BREAKAWAY_OK = 0x00000800,
///
/// Allows any process associated with the job to create child processes that are not associated with the job. If the job is
/// nested and its immediate job object allows breakaway, the child process breaks away from the immediate job object and from
/// each job in the parent job chain, moving up the hierarchy until it reaches a job that does not permit breakaway. If the
/// immediate job object does not allow breakaway, the child process does not break away even if jobs in its parent job chain
/// allow it.This limit requires use of a JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure. Its BasicLimitInformation member is a
/// JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK = 0x00001000,
///
/// Causes all processes associated with the job to terminate when the last handle to the job is closed.This limit requires use
/// of a JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure. Its BasicLimitInformation member is a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE = 0x00002000,
///
/// Allows processes to use a subset of the processor affinity for all processes associated with the job. This value must be
/// combined with JOB_OBJECT_LIMIT_AFFINITY. Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is
/// supported starting with Windows 7 and Windows Server 2008 R2.
///
JOB_OBJECT_LIMIT_SUBSET_AFFINITY = 0x00004000,
/// The job has a committed minimum memory notification limit. The JobLowMemoryLimit member contains more information.
JOB_OBJECT_LIMIT_JOB_MEMORY_LOW = 0x00008000,
/// The job has an I/O read bytes notification limit. The IoReadBytesLimit member contains more information.
JOB_OBJECT_LIMIT_JOB_READ_BYTES = 0x00010000,
/// The job has an I/O write bytes notification limit. The IoWriteBytesLimit member contains more information.
JOB_OBJECT_LIMIT_JOB_WRITE_BYTES = 0x00020000,
///
/// The job has notification limit for the extent to which a job can exceed its CPU rate control limit. The
/// RateControlToleranceLimit member contains more information.
///
JOB_OBJECT_LIMIT_RATE_CONTROL = 0x00040000,
///
/// The job has notification limit for the extent to which a job can exceed its CPU rate control limit. The
/// CpuRateControlToleranceLimit member contains more information.
///
JOB_OBJECT_LIMIT_CPU_RATE_CONTROL = JOB_OBJECT_LIMIT_RATE_CONTROL,
///
/// The job has notification limit for the extent to which a job can exceed its I/O rate control limit. The
/// IoRateControlToleranceLimit member contains more information.
///
JOB_OBJECT_LIMIT_IO_RATE_CONTROL = 0x00080000,
///
/// The job has notification limit for the extent to which a job can exceed its network rate control limit. The
/// NetRateControlToleranceLimit member contains more information.
///
JOB_OBJECT_LIMIT_NET_RATE_CONTROL = 0x00100000,
}
///
/// Specifies the extent to which a job can exceed its CPU rate control limits during the interval specified by the
/// RateControlToleranceInterval member.
///
public enum JOBOBJECT_RATE_CONTROL_TOLERANCE
{
/// The job can exceed its CPU rate control limits for 20% of the tolerance interval.
ToleranceLow = 1,
/// The job can exceed its CPU rate control limits for 40% of the tolerance interval.
ToleranceMedium,
/// The job can exceed its CPU rate control limits for 60% of the tolerance interval.
ToleranceHigh
}
///
/// Specifies the interval during which a job's CPU usage is monitored to determine whether the job has exceeded its CPU rate control limits.
///
public enum JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL
{
/// The tolerance interval is 10 seconds.
ToleranceIntervalShort = 1,
/// The tolerance interval is one minute.
ToleranceIntervalMedium,
/// The tolerance interval is 10 minutes.
ToleranceIntervalLong
}
/// The security limitations for the job.
[Flags]
public enum JOBOBJECT_SECURITY_FLAGS
{
/// Prevents any process in the job from using a token that specifies the local administrators group.
JOB_OBJECT_SECURITY_NO_ADMIN = 0x00000001,
/// Prevents any process in the job from using a token that was not created with the CreateRestrictedToken function.
JOB_OBJECT_SECURITY_RESTRICTED_TOKEN = 0x00000002,
/// Forces processes in the job to run under a specific token. Requires a token handle in the JobToken member.
JOB_OBJECT_SECURITY_ONLY_TOKEN = 0x00000004,
///
/// Applies a filter to the token when a process impersonates a client. Requires at least one of the following members to be set:
/// SidsToDisable, PrivilegesToDelete, or RestrictedSids.
///
JOB_OBJECT_SECURITY_FILTER_TOKENS = 0x00000008,
}
/// The restriction class for the user interface.
[Flags]
public enum JOBOBJECT_UILIMIT_FLAGS
{
///
JOB_OBJECT_UILIMIT_NONE = 0x00000000,
///
/// Prevents processes associated with the job from using USER handles owned by processes not associated with the same job.
///
JOB_OBJECT_UILIMIT_HANDLES = 0x00000001,
/// Prevents processes associated with the job from reading data from the clipboard.
JOB_OBJECT_UILIMIT_READCLIPBOARD = 0x00000002,
/// Prevents processes associated with the job from writing data to the clipboard.
JOB_OBJECT_UILIMIT_WRITECLIPBOARD = 0x00000004,
///
/// Prevents processes associated with the job from changing system parameters by using the SystemParametersInfo function.
///
JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS = 0x00000008,
/// Prevents processes associated with the job from calling the ChangeDisplaySettings function.
JOB_OBJECT_UILIMIT_DISPLAYSETTINGS = 0x00000010,
///
/// Prevents processes associated with the job from accessing global atoms. When this flag is used, each job has its own atom table.
///
JOB_OBJECT_UILIMIT_GLOBALATOMS = 0x00000020,
///
/// Prevents processes associated with the job from creating desktops and switching desktops using the CreateDesktop and
/// SwitchDesktop functions.
///
JOB_OBJECT_UILIMIT_DESKTOP = 0x00000040,
/// Prevents processes associated with the job from calling the ExitWindows or ExitWindowsEx function.
JOB_OBJECT_UILIMIT_EXITWINDOWS = 0x00000080,
/// All values.
JOB_OBJECT_UILIMIT_ALL = 0x000000FF,
}
/// The information class for the limits to be queried.
public enum JOBOBJECTINFOCLASS
{
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_ACCOUNTING_INFORMATION structure.
[CorrespondingType(typeof(JOBOBJECT_BASIC_ACCOUNTING_INFORMATION), CorrespondingAction.Get)]
JobObjectBasicAccountingInformation = 1,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
[CorrespondingType(typeof(JOBOBJECT_BASIC_LIMIT_INFORMATION), CorrespondingAction.GetSet)]
JobObjectBasicLimitInformation,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_PROCESS_ID_LIST structure.
[CorrespondingType(typeof(JOBOBJECT_BASIC_PROCESS_ID_LIST), CorrespondingAction.Get)]
JobObjectBasicProcessIdList,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_UI_RESTRICTIONS structure.
[CorrespondingType(typeof(JOBOBJECT_BASIC_UI_RESTRICTIONS), CorrespondingAction.GetSet)]
JobObjectBasicUIRestrictions,
/// This flag is not supported. Applications must set security limits individually for each process.
[CorrespondingType(typeof(JOBOBJECT_SECURITY_LIMIT_INFORMATION), CorrespondingAction.GetSet)]
JobObjectSecurityLimitInformation,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_END_OF_JOB_TIME_INFORMATION structure.
[CorrespondingType(typeof(JOBOBJECT_END_OF_JOB_TIME_INFORMATION), CorrespondingAction.GetSet)]
JobObjectEndOfJobTimeInformation,
/// The job object associate completion port information
[CorrespondingType(typeof(JOBOBJECT_ASSOCIATE_COMPLETION_PORT), CorrespondingAction.Set)]
JobObjectAssociateCompletionPortInformation,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION structure.
[CorrespondingType(typeof(JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION), CorrespondingAction.Get)]
JobObjectBasicAndIoAccountingInformation,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure.
[CorrespondingType(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION), CorrespondingAction.GetSet)]
JobObjectExtendedLimitInformation,
/// Undocumented.
JobObjectJobSetInformation,
///
/// The lpJobObjectInfo parameter is a pointer to a buffer that receives the list of processor groups to which the job is
/// currently assigned. The variable pointed to by the lpReturnLength parameter is set to the size of the group data. Divide this
/// value by sizeof(USHORT) to determine the number of groups.
///
[CorrespondingType(typeof(ushort[]), CorrespondingAction.GetSet)]
JobObjectGroupInformation,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION structure.
[CorrespondingType(typeof(JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION), CorrespondingAction.GetSet)]
JobObjectNotificationLimitInformation,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_LIMIT_VIOLATION_INFORMATION structure.
[CorrespondingType(typeof(JOBOBJECT_LIMIT_VIOLATION_INFORMATION), CorrespondingAction.Get)]
JobObjectLimitViolationInformation,
///
/// The lpJobObjectInfo parameter is a pointer to a buffer that receives an array of GROUP_AFFINITY structures that indicate the
/// affinity of the job in the processor groups to which the job is currently assigned. The variable pointed to by the
/// lpReturnLength parameter is set to the size of the group affinity data. Divide this value by sizeof(GROUP_AFFINITY) to
/// determine the number of groups.
///
[CorrespondingType(typeof(GROUP_AFFINITY[]), CorrespondingAction.GetSet)]
JobObjectGroupInformationEx,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_CPU_RATE_CONTROL_INFORMATION structure.
[CorrespondingType(typeof(JOBOBJECT_CPU_RATE_CONTROL_INFORMATION), CorrespondingAction.GetSet)]
JobObjectCpuRateControlInformation,
/// Undocumented.
JobObjectCompletionFilter,
/// Undocumented.
JobObjectCompletionCounter,
/// Undocumented.
JobObjectReserved1Information = 18,
/// Undocumented.
JobObjectReserved2Information,
/// Undocumented.
JobObjectReserved3Information,
/// Undocumented.
JobObjectReserved4Information,
/// Undocumented.
JobObjectReserved5Information,
/// Undocumented.
JobObjectReserved6Information,
/// Undocumented.
JobObjectReserved7Information,
/// Undocumented.
JobObjectReserved8Information,
/// Undocumented.
JobObjectReserved9Information,
/// Undocumented.
JobObjectReserved10Information,
/// Undocumented.
JobObjectReserved11Information,
/// Undocumented.
JobObjectReserved12Information,
/// Undocumented.
JobObjectReserved13Information,
/// Undocumented.
JobObjectReserved14Information = 31,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NET_RATE_CONTROL_INFORMATION structure.
[CorrespondingType(typeof(JOBOBJECT_NET_RATE_CONTROL_INFORMATION), CorrespondingAction.GetSet)]
JobObjectNetRateControlInformation,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION_2 structure.
[CorrespondingType(typeof(JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION_2), CorrespondingAction.GetSet)]
JobObjectNotificationLimitInformation2,
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_LIMIT_VIOLATION_INFORMATION_2 structure.
[CorrespondingType(typeof(JOBOBJECT_LIMIT_VIOLATION_INFORMATION_2), CorrespondingAction.GetSet)]
JobObjectLimitViolationInformation2,
/// Undocumented.
JobObjectCreateSilo,
/// Undocumented.
JobObjectSiloBasicInformation,
/// Undocumented.
JobObjectReserved15Information = 37,
/// Undocumented.
JobObjectReserved16Information = 38,
/// Undocumented.
JobObjectReserved17Information = 39,
/// Undocumented.
JobObjectReserved18Information = 40,
/// Undocumented.
JobObjectReserved19Information = 41,
/// Undocumented.
JobObjectReserved20Information = 42,
/// Undocumented.
JobObjectReserved21Information = 43,
/// Undocumented.
JobObjectReserved22Information = 44,
/// Undocumented.
JobObjectReserved23Information = 45,
/// Undocumented.
JobObjectReserved24Information = 46,
/// Undocumented.
JobObjectReserved25Information = 47,
}
/// Assigns a process to an existing job object.
///
/// A handle to the job object to which the process will be associated. The CreateJobObject or OpenJobObject function
/// returns this handle. The handle must have the JOB_OBJECT_ASSIGN_PROCESS access right. For more information, see Job Object
/// Security and Access Rights.
///
///
///
/// A handle to the process to associate with the job object. The handle must have the PROCESS_SET_QUOTA and PROCESS_TERMINATE access
/// rights. For more information, see Process Security and Access Rights.
///
///
/// If the process is already associated with a job, the job specified by hJob must be empty or it must be in the hierarchy of nested
/// jobs to which the process already belongs, and it cannot have UI limits set ( SetInformationJobObject with
/// JobObjectBasicUIRestrictions). For more information, see Remarks.
///
///
/// Windows 7, Windows Server 2008 R2, Windows XP with SP3, Windows Server 2008, Windows Vista and Windows Server 2003: The
/// process must not already be assigned to a job; if it is, the function fails with ERROR_ACCESS_DENIED. This behavior changed
/// starting in Windows 8 and Windows Server 2012.
///
/// Terminal Services: All processes within a job must run within the same session as the job.
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// BOOL WINAPI AssignProcessToJobObject( _In_ HANDLE hJob, _In_ HANDLE hProcess); https://msdn.microsoft.com/en-us/library/windows/desktop/ms681949(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "ms681949")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AssignProcessToJobObject([In] HJOB hJob, [In] HPROCESS hProcess);
///
/// Creates or opens a job object.
///
///
///
/// A pointer to a SECURITY_ATTRIBUTES structure that specifies the security descriptor for the job object and determines whether
/// child processes can inherit the returned handle. If lpJobAttributes is NULL, the job object gets a default security
/// descriptor and the handle cannot be inherited. The ACLs in the default security descriptor for a job object come from the primary
/// or impersonation token of the creator.
///
///
///
/// The name of the job. The name is limited to MAX_PATH characters. Name comparison is case-sensitive.
/// If lpName is NULL, the job is created without a name.
///
/// If lpName matches the name of an existing event, semaphore, mutex, waitable timer, or file-mapping object, the function fails and
/// the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because these objects share the same namespace.
///
/// The object can be created in a private namespace. For more information, see Object Namespaces.
///
/// Terminal Services: The name can have a "Global" or "Local" prefix to explicitly create the object in the global or session
/// namespace. The remainder of the name can contain any character except the backslash character (). For more information, see
/// Kernel Object Namespaces.
///
///
///
///
/// If the function succeeds, the return value is a handle to the job object. The handle has the JOB_OBJECT_ALL_ACCESS access
/// right. If the object existed before the function call, the function returns a handle to the existing job object and GetLastError
/// returns ERROR_ALREADY_EXISTS.
///
/// If the function fails, the return value is NULL. To get extended error information, call GetLastError.
///
///
///
/// When a job is created, its accounting information is initialized to zero, all limits are inactive, and there are no associated
/// processes. To assign a process to a job object, use the AssignProcessToJobObject function. To set limits for a job, use the
/// SetInformationJobObject function. To query accounting information, use the QueryInformationJobObject function.
///
///
/// All processes associated with a job must run in the same session. A job is associated with the session of the first process to be
/// assigned to the job.
///
/// Windows Server 2003 and Windows XP: A job is associated with the session of the process that created it.
///
/// To close a job object handle, use the CloseHandle function. The job is destroyed when its last handle has been closed and all
/// associated processes have exited. However, if the job has the JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE flag specified, closing
/// the last job object handle terminates all associated processes and then destroys the job object itself.
///
///
/// To compile an application that uses this function, define _WIN32_WINNT as 0x0500 or later. For more information, see Using
/// the Windows Headers.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createjobobjecta HANDLE CreateJobObjectA(
// LPSECURITY_ATTRIBUTES lpJobAttributes, LPCSTR lpName );
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winbase.h", MSDNShortId = "ca6a044f-67ed-4a9c-9aeb-69dd77652854")]
public static extern SafeHJOB CreateJobObject([In, Optional] SECURITY_ATTRIBUTES lpJobAttributes, [In, Optional] string lpName);
///
/// Frees memory that a function related to job objects allocated. Functions related to job objects that allocate memory include QueryIoRateControlInformationJobObject.
///
/// A pointer to the buffer of allocated memory that you want to free.
/// This function does not return a value.
// VOID WINAPI FreeMemoryJobObject( _In_ VOID *Buffer); https://msdn.microsoft.com/en-us/library/windows/desktop/mt280121(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Jobapi2.h", MSDNShortId = "mt280121")]
public static extern void FreeMemoryJobObject(IntPtr Buffer);
/// Determines whether the process is running in the specified job.
///
///
/// A handle to the process to be tested. The handle must have the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION
/// access right. For more information, see Process Security and Access Rights.
///
/// Windows Server 2003 and Windows XP: The handle must have the PROCESS_QUERY_INFORMATION access right.
///
///
/// A handle to the job. If this parameter is NULL, the function tests if the process is running under any job.
///
/// If this parameter is not NULL, the handle must have the JOB_OBJECT_QUERY access right. For more information, see Job Object
/// Security and Access Rights.
///
///
/// A pointer to a value that receives TRUE if the process is running in the job, and FALSE otherwise.
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// BOOL WINAPI IsProcessInJob( _In_ HANDLE ProcessHandle, _In_opt_ HANDLE JobHandle, _Out_ PBOOL Result); https://msdn.microsoft.com/en-us/library/windows/desktop/ms684127(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "ms684127")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsProcessInJob([In] HPROCESS ProcessHandle, [In] HJOB JobHandle, [MarshalAs(UnmanagedType.Bool)] out bool Result);
/// Opens an existing job object.
///
/// The access to the job object. This parameter can be one or more of the job object access rights. This access right is checked
/// against any security descriptor for the object.
///
///
/// If this value is TRUE, processes created by this process will inherit the handle. Otherwise, the processes do not inherit this handle.
///
///
/// The name of the job to be opened. Name comparisons are case sensitive.
/// This function can open objects in a private namespace. For more information, see Object Namespaces.
///
/// Terminal Services: The name can have a "Global\" or "Local\" prefix to explicitly open the object in the global or session
/// namespace. The remainder of the name can contain any character except the backslash character (\). For more information, see
/// Kernel Object Namespaces.
///
///
///
/// If the function succeeds, the return value is a handle to the job. The handle provides the requested access to the job.
/// If the function fails, the return value is NULL. To get extended error information, call GetLastError.
///
// HANDLE WINAPI OpenJobObject( _In_ DWORD dwDesiredAccess, _In_ BOOL bInheritHandles, _In_ LPCTSTR lpName); https://msdn.microsoft.com/en-us/library/windows/desktop/ms684312(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("WinBase.h", MSDNShortId = "ms684312")]
public static extern SafeHJOB OpenJobObject(uint dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandles, string lpName);
/// Retrieves limit and job state information from the job object.
///
///
/// A handle to the job whose information is being queried. The CreateJobObject or OpenJobObject function returns this
/// handle. The handle must have the JOB_OBJECT_QUERY access right. For more information, see Job Object Security and Access Rights.
///
///
/// If this value is NULL and the calling process is associated with a job, the job associated with the calling process is used. If
/// the job is nested, the immediate job of the calling process is used.
///
///
///
/// The information class for the limits to be queried. This parameter can be one of the following values.
///
///
///
/// Value
/// Meaning
///
/// -
/// JobObjectBasicAccountingInformation1
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_ACCOUNTING_INFORMATION structure.
///
/// -
/// JobObjectBasicAndIoAccountingInformation8
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION structure.
///
/// -
/// JobObjectBasicLimitInformation2
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
/// -
/// JobObjectBasicProcessIdList3
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_PROCESS_ID_LIST structure.
///
/// -
/// JobObjectBasicUIRestrictions4
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_UI_RESTRICTIONS structure.
///
/// -
/// JobObjectCpuRateControlInformation15
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_CPU_RATE_CONTROL_INFORMATION structure. Windows 7, Windows Server 2008
/// R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectEndOfJobTimeInformation6
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_END_OF_JOB_TIME_INFORMATION structure.
///
/// -
/// JobObjectExtendedLimitInformation9
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure.
///
/// -
/// JobObjectGroupInformation11
///
/// The lpJobObjectInfo parameter is a pointer to a buffer that receives the list of processor groups to which the job is currently
/// assigned. The variable pointed to by the lpReturnLength parameter is set to the size of the group data. Divide this value by to
/// determine the number of groups.Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectGroupInformationEx14
///
/// The lpJobObjectInfo parameter is a pointer to a buffer that receives an array of GROUP_AFFINITY structures that indicate the
/// affinity of the job in the processor groups to which the job is currently assigned. The variable pointed to by the lpReturnLength
/// parameter is set to the size of the group affinity data. Divide this value by to determine the number of groups.Windows 7,
/// Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectLimitViolationInformation13
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_LIMIT_VIOLATION_INFORMATION structure. Windows 7, Windows Server 2008
/// R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectLimitViolationInformation235
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_LIMIT_VIOLATION_INFORMATION_2 structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNetRateControlInformation32
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NET_RATE_CONTROL_INFORMATION structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNotificationLimitInformation12
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION structure. Windows 7, Windows Server
/// 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNotificationLimitInformation234
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION_2 structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectSecurityLimitInformation5
///
/// This flag is not supported. Applications must set security limits individually for each process. Windows Server 2003 and Windows
/// XP: The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_SECURITY_LIMIT_INFORMATION structure.
///
///
///
///
///
///
/// The limit or job state information. The format of this data depends on the value of the JobObjectInfoClass parameter.
///
///
/// The count of the job information being queried, in bytes. This value depends on the value of the JobObjectInfoClass parameter.
///
///
/// A pointer to a variable that receives the length of data written to the structure pointed to by the lpJobObjectInfo parameter.
/// Specify NULL to not receive this information.
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// BOOL WINAPI QueryInformationJobObject( _In_opt_ HANDLE hJob, _In_ JOBOBJECTINFOCLASS JobObjectInfoClass, _Out_ LPVOID
// lpJobObjectInfo, _In_ DWORD cbJobObjectInfoLength, _Out_opt_ LPDWORD lpReturnLength); https://msdn.microsoft.com/en-us/library/windows/desktop/ms684925(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "ms684925")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool QueryInformationJobObject([In] HJOB hJob, JOBOBJECTINFOCLASS JobObjectInfoClass, IntPtr lpJobObjectInfo,
uint cbJobObjectInfoLength, out uint lpReturnLength);
/// Retrieves limit and job state information from the job object.
///
///
/// A handle to the job whose information is being queried. The CreateJobObject or OpenJobObject function returns this
/// handle. The handle must have the JOB_OBJECT_QUERY access right. For more information, see Job Object Security and Access Rights.
///
///
/// If this value is NULL and the calling process is associated with a job, the job associated with the calling process is used. If
/// the job is nested, the immediate job of the calling process is used.
///
///
///
/// The information class for the limits to be queried. This parameter can be one of the following values.
///
///
///
/// Value
/// Meaning
///
/// -
/// JobObjectBasicAccountingInformation1
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_ACCOUNTING_INFORMATION structure.
///
/// -
/// JobObjectBasicAndIoAccountingInformation8
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION structure.
///
/// -
/// JobObjectBasicLimitInformation2
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
/// -
/// JobObjectBasicProcessIdList3
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_PROCESS_ID_LIST structure.
///
/// -
/// JobObjectBasicUIRestrictions4
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_UI_RESTRICTIONS structure.
///
/// -
/// JobObjectCpuRateControlInformation15
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_CPU_RATE_CONTROL_INFORMATION structure. Windows 7, Windows Server 2008
/// R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectEndOfJobTimeInformation6
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_END_OF_JOB_TIME_INFORMATION structure.
///
/// -
/// JobObjectExtendedLimitInformation9
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure.
///
/// -
/// JobObjectGroupInformation11
///
/// The lpJobObjectInfo parameter is a pointer to a buffer that receives the list of processor groups to which the job is currently
/// assigned. The variable pointed to by the lpReturnLength parameter is set to the size of the group data. Divide this value by to
/// determine the number of groups.Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectGroupInformationEx14
///
/// The lpJobObjectInfo parameter is a pointer to a buffer that receives an array of GROUP_AFFINITY structures that indicate the
/// affinity of the job in the processor groups to which the job is currently assigned. The variable pointed to by the lpReturnLength
/// parameter is set to the size of the group affinity data. Divide this value by to determine the number of groups.Windows 7,
/// Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectLimitViolationInformation13
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_LIMIT_VIOLATION_INFORMATION structure. Windows 7, Windows Server 2008
/// R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectLimitViolationInformation235
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_LIMIT_VIOLATION_INFORMATION_2 structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNetRateControlInformation32
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NET_RATE_CONTROL_INFORMATION structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNotificationLimitInformation12
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION structure. Windows 7, Windows Server
/// 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNotificationLimitInformation234
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION_2 structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectSecurityLimitInformation5
///
/// This flag is not supported. Applications must set security limits individually for each process. Windows Server 2003 and Windows
/// XP: The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_SECURITY_LIMIT_INFORMATION structure.
///
///
///
///
///
/// The limit or job state information. The format of this data depends on the value of the JobObjectInfoClass parameter.
public static T QueryInformationJobObject([In] HJOB hJob, JOBOBJECTINFOCLASS jobObjectInfoClass) where T : struct
{
if (!CorrespondingTypeAttribute.CanGet(jobObjectInfoClass, typeof(T))) throw new ArgumentException("Type mismatch.", nameof(jobObjectInfoClass));
using (var mem = SafeHGlobalHandle.CreateFromStructure())
{
if (!QueryInformationJobObject(hJob, jobObjectInfoClass, mem, mem.Size, out _))
Win32Error.ThrowLastError();
return mem.ToStructure();
}
}
/// Gets information about the control of the I/O rate for a job object.
///
///
/// A handle to the job to query for information. Get this handle from the CreateJobObject or OpenJobObject function.
/// The handle must have the JOB_OBJECT_QUERY access right. For more information about access rights, see Job Object Security
/// and Access Rights.
///
///
/// If this value is NULL and the process that calls QueryIoRateControlInformationJobObject is associated with a job, the
/// function uses job that is associated with the process. If the job is nested within another job, the function uses the immediate
/// job for the process.
///
///
///
/// The name of the volume to query. If this value is NULL, the function gets the information about I/O rate control for the job for
/// all of the volumes for the system.
///
///
/// A pointer to array of JOBOBJECT_IO_RATE_CONTROL_INFORMATION structures that contain the information about I/O rate control
/// for the job. Your code must free the memory for this array by calling the FreeMemoryJobObject function with the address of
/// the array.
///
///
/// The number of JOBOBJECT_IO_RATE_CONTROL_INFORMATION structures that the function allocated in the array to which the
/// InfoBlocks parameter points.
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// DWORD WINAPI QueryIoRateControlInformationJobObject( _In_opt_ HANDLE hJob, _In_opt_ PCWSTR VolumeName, _Out_
// JOBOBJECT_IO_RATE_CONTROL_INFORMATION **InfoBlocks, _Out_ ULONG *InfoBlockCount); https://msdn.microsoft.com/en-us/library/windows/desktop/mt280127(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("Jobapi2.h", MSDNShortId = "mt280127")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool QueryIoRateControlInformationJobObject(HJOB hJob, [MarshalAs(UnmanagedType.LPWStr)] string VolumeName, out IntPtr InfoBlocks, out uint InfoBlockCount);
/// Gets information about the control of the I/O rate for a job object.
///
///
/// A handle to the job to query for information. Get this handle from the CreateJobObject or OpenJobObject function.
/// The handle must have the JOB_OBJECT_QUERY access right. For more information about access rights, see Job Object Security
/// and Access Rights.
///
///
/// If this value is NULL and the process that calls QueryIoRateControlInformationJobObject is associated with a job, the
/// function uses job that is associated with the process. If the job is nested within another job, the function uses the immediate
/// job for the process.
///
///
///
/// The name of the volume to query. If this value is NULL, the function gets the information about I/O rate control for the job for
/// all of the volumes for the system.
///
///
/// An array of JOBOBJECT_IO_RATE_CONTROL_INFORMATION structures that contain the information about I/O rate control for the
/// job. Your code must free the memory for this array by calling the FreeMemoryJobObject function with the address of the array.
///
[PInvokeData("Jobapi2.h", MSDNShortId = "mt280127")]
public static JOBOBJECT_IO_RATE_CONTROL_INFORMATION[] QueryIoRateControlInformationJobObject(HJOB hJob, string VolumeName = null)
{
var relId = int.Parse(Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", "0").ToString());
if (relId == 0 || relId >= 1607)
throw new NotSupportedException("This function is only supported on Windows 10 releases before 1607.");
if (!QueryIoRateControlInformationJobObject(hJob, VolumeName, out var ib, out var ibc))
Win32Error.ThrowLastError();
try
{
return ib.ToArray((int)ibc);
}
finally
{
FreeMemoryJobObject(ib);
}
}
/// Sets limits for a job object.
///
/// A handle to the job whose limits are being set. The CreateJobObject or OpenJobObject function returns this handle. The handle
/// must have the JOB_OBJECT_SET_ATTRIBUTES access right. For more information, see Job Object Security and Access Rights.
///
///
/// The information class for the limits to be set. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// JobObjectAssociateCompletionPortInformation 7
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_ASSOCIATE_COMPLETION_PORT structure.
///
/// -
/// JobObjectBasicLimitInformation 2
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
/// -
/// JobObjectBasicUIRestrictions 4
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_UI_RESTRICTIONS structure.
///
/// -
/// JobObjectCpuRateControlInformation 15
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_CPU_RATE_CONTROL_INFORMATION structure. Windows 7, Windows Server 2008
/// R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectEndOfJobTimeInformation 6
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_END_OF_JOB_TIME_INFORMATION structure.
///
/// -
/// JobObjectExtendedLimitInformation 9
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure.
///
/// -
/// JobObjectGroupInformation 11
///
/// The lpJobObjectInfo parameter is a pointer to a USHORT value that specifies the list of processor groups to assign the job to.
/// The cbJobObjectInfoLength parameter is set to the size of the group data. Divide this value by to determine the number of groups.
/// Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectGroupInformationEx 14
///
/// The lpJobObjectInfo parameter is a pointer to a buffer that contains an array of GROUP_AFFINITY structures that specify the
/// affinity of the job for the processor groups to which the job is currently assigned. The cbJobObjectInfoLength parameter is set
/// to the size of the group affinity data. Divide this value by to determine the number of groups. Windows 7, Windows Server 2008
/// R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectLimitViolationInformation2 35
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_LIMIT_VIOLATION_INFORMATION_2 structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNetRateControlInformation 32
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NET_RATE_CONTROL_INFORMATION structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNotificationLimitInformation 12
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION structure. Windows 7, Windows Server
/// 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNotificationLimitInformation2 34
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION_2 structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectSecurityLimitInformation 5
///
/// This flag is not supported. Applications must set security limitations individually for each process. Windows Server 2003 and
/// Windows XP: The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_SECURITY_LIMIT_INFORMATION structure. The hJob handle must
/// have the JOB_OBJECT_SET_SECURITY_ATTRIBUTES access right associated with it.
///
///
///
///
///
/// The limits or job state to be set for the job. The format of this data depends on the value of JobObjectInfoClass.
///
/// The size of the job information being set, in bytes.
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
///
///
/// Use the SetInformationJobObject function to set several limits in a single call. To establish the limits one at a time or
/// change a subset of the limits, call the QueryInformationJobObject function to obtain the current limits, modify these limits, and
/// then call SetInformationJobObject.
///
///
/// You must set security limits individually for each process associated with a job object, rather than setting them for the job
/// object itself. For information, see Process Security and Access Rights.
///
///
/// Windows Server 2003 and Windows XP: Use the SetInformationJobObject function to set security limits for the job object.
///
///
/// To compile an application that uses this function, define _WIN32_WINNT as 0x0500 or later. For more information, see Using the
/// Windows Headers.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/jobapi2/nf-jobapi2-setinformationjobobject BOOL SetInformationJobObject(
// HANDLE hJob, JOBOBJECTINFOCLASS JobObjectInformationClass, LPVOID lpJobObjectInformation, DWORD cbJobObjectInformationLength );
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("jobapi2.h", MSDNShortId = "46f7c579-e8d3-4434-a6ce-56573cd84387")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetInformationJobObject([In] HJOB hJob, JOBOBJECTINFOCLASS JobObjectInformationClass, [In] IntPtr lpJobObjectInformation, uint cbJobObjectInformationLength);
/// Sets limits for a job object.
///
/// A handle to the job whose limits are being set. The CreateJobObject or OpenJobObject function returns this handle. The handle
/// must have the JOB_OBJECT_SET_ATTRIBUTES access right. For more information, see Job Object Security and Access Rights.
///
///
/// The information class for the limits to be set. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// JobObjectAssociateCompletionPortInformation 7
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_ASSOCIATE_COMPLETION_PORT structure.
///
/// -
/// JobObjectBasicLimitInformation 2
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
/// -
/// JobObjectBasicUIRestrictions 4
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_BASIC_UI_RESTRICTIONS structure.
///
/// -
/// JobObjectCpuRateControlInformation 15
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_CPU_RATE_CONTROL_INFORMATION structure. Windows 7, Windows Server 2008
/// R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectEndOfJobTimeInformation 6
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_END_OF_JOB_TIME_INFORMATION structure.
///
/// -
/// JobObjectExtendedLimitInformation 9
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure.
///
/// -
/// JobObjectGroupInformation 11
///
/// The lpJobObjectInfo parameter is a pointer to a USHORT value that specifies the list of processor groups to assign the job to.
/// The cbJobObjectInfoLength parameter is set to the size of the group data. Divide this value by to determine the number of groups.
/// Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectGroupInformationEx 14
///
/// The lpJobObjectInfo parameter is a pointer to a buffer that contains an array of GROUP_AFFINITY structures that specify the
/// affinity of the job for the processor groups to which the job is currently assigned. The cbJobObjectInfoLength parameter is set
/// to the size of the group affinity data. Divide this value by to determine the number of groups. Windows 7, Windows Server 2008
/// R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectLimitViolationInformation2 35
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_LIMIT_VIOLATION_INFORMATION_2 structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNetRateControlInformation 32
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NET_RATE_CONTROL_INFORMATION structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNotificationLimitInformation 12
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION structure. Windows 7, Windows Server
/// 2008 R2, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectNotificationLimitInformation2 34
///
/// The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION_2 structure. Windows 8.1, Windows Server
/// 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Server 2008 R2, Windows Server 2008, Windows Vista, Windows Server
/// 2003 and Windows XP: This flag is not supported.
///
///
/// -
/// JobObjectSecurityLimitInformation 5
///
/// This flag is not supported. Applications must set security limitations individually for each process. Windows Server 2003 and
/// Windows XP: The lpJobObjectInfo parameter is a pointer to a JOBOBJECT_SECURITY_LIMIT_INFORMATION structure. The hJob handle must
/// have the JOB_OBJECT_SET_SECURITY_ATTRIBUTES access right associated with it.
///
///
///
///
///
/// The limits or job state to be set for the job. The format of this data depends on the value of JobObjectInfoClass.
///
[PInvokeData("jobapi2.h", MSDNShortId = "46f7c579-e8d3-4434-a6ce-56573cd84387")]
public static void SetInformationJobObject([In] HJOB hJob, JOBOBJECTINFOCLASS jobObjectInfoClass, in T jobObjectInfo) where T : struct
{
if (!CorrespondingTypeAttribute.CanSet(jobObjectInfoClass, typeof(T))) throw new ArgumentException("Type mismatch.", nameof(jobObjectInfoClass));
using (var mem = SafeHGlobalHandle.CreateFromStructure(jobObjectInfo))
if (!SetInformationJobObject(hJob, jobObjectInfoClass, mem, mem.Size))
Win32Error.ThrowLastError();
}
/// Sets I/O limits on a job object.
///
/// A handle to the job on which to set I/O limits. Get this handle from the CreateJobObject or OpenJobObject function.
/// The handle must have the JOB_OBJECT_SET_ATTRIBUTES access right. For more information about access rights, see Job Object
/// Security and Access Rights.
///
///
/// A pointer to a JOBOBJECT_IO_RATE_CONTROL_INFORMATION structure that specifies the I/O limits to set for the job.
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// DWORD WINAPI SetIoRateControlInformationJobObject( _In_ HANDLE hJob, _In_ JOBOBJECT_IO_RATE_CONTROL_INFORMATION
// *IoRateControlInfo); https://msdn.microsoft.com/en-us/library/windows/desktop/mt280128(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("Jobapi2.h", MSDNShortId = "mt280128")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetIoRateControlInformationJobObject(HJOB hJob, in JOBOBJECT_IO_RATE_CONTROL_INFORMATION IoRateControlInfo);
///
/// Terminates all processes currently associated with the job. If the job is nested, this function terminates all processes
/// currently associated with the job and all of its child jobs in the hierarchy.
///
///
///
/// A handle to the job whose processes will be terminated. The CreateJobObject or OpenJobObject function returns this
/// handle. This handle must have the JOB_OBJECT_TERMINATE access right. For more information, see Job Object Security and Access Rights.
///
///
/// The handle for each process in the job object must have the PROCESS_TERMINATE access right. For more information, see Process
/// Security and Access Rights.
///
///
///
/// The exit code to be used by all processes and threads in the job object. Use the GetExitCodeProcess function to retrieve
/// each process's exit value. Use the GetExitCodeThread function to retrieve each thread's exit value.
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// BOOL WINAPI TerminateJobObject( _In_ HANDLE hJob, _In_ UINT uExitCode); https://msdn.microsoft.com/en-us/library/windows/desktop/ms686709(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "ms686709")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool TerminateJobObject([In] HJOB hJob, uint uExitCode);
/// Provides a handle to a job object.
[StructLayout(LayoutKind.Sequential)]
public struct HJOB : ISyncHandle
{
private readonly IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HJOB(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HJOB NULL => new HJOB(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HJOB h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HJOB(IntPtr h) => new HJOB(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HJOB h1, HJOB h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HJOB h1, HJOB h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HJOB h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
///
/// Contains I/O accounting information for a process or a job object. For a job object, the counters include all operations
/// performed by all processes that have ever been associated with the job, in addition to all processes currently associated with
/// the job.
///
// typedef struct _IO_COUNTERS { ULONGLONG ReadOperationCount; ULONGLONG WriteOperationCount; ULONGLONG OtherOperationCount;
// ULONGLONG ReadTransferCount; ULONGLONG WriteTransferCount; ULONGLONG OtherTransferCount;} IO_COUNTERS, *PIO_COUNTERS; https://msdn.microsoft.com/en-us/library/windows/desktop/ms684125(v=vs.85).aspx
[PInvokeData("WinNT.h", MSDNShortId = "ms684125")]
[StructLayout(LayoutKind.Sequential)]
public struct IO_COUNTERS
{
/// The number of read operations performed.
public ulong ReadOperationCount;
/// The number of write operations performed.
public ulong WriteOperationCount;
/// The number of I/O operations performed, other than read and write operations.
public ulong OtherOperationCount;
/// The number of bytes read.
public ulong ReadTransferCount;
/// The number of bytes written.
public ulong WriteTransferCount;
/// The number of bytes transferred during operations other than read and write operations.
public ulong OtherTransferCount;
}
///
/// Contains information used to associate a completion port with a job. You can associate one completion port with a job.
///
[PInvokeData("WinNT.h", MSDNShortId = "ms684141")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_ASSOCIATE_COMPLETION_PORT
{
///
/// The value to use in the dwCompletionKey parameter of PostQueuedCompletionStatus when messages are sent on behalf of the job.
///
public UIntPtr CompletionKey;
///
/// The completion port to use in the CompletionPort parameter of the PostQueuedCompletionStatus function when messages are sent
/// on behalf of the job.
///
/// Windows 8, Windows Server 2012, Windows 8.1, Windows Server 2012 R2, Windows 10 and Windows Server 2016: Specify NULL to
/// remove the association between the current completion port and the job.
///
///
public HANDLE CompletionPort;
}
/// Contains basic accounting information for a job object.
// typedef struct _JOBOBJECT_BASIC_ACCOUNTING_INFORMATION { LARGE_INTEGER TotalUserTime; LARGE_INTEGER TotalKernelTime; LARGE_INTEGER
// ThisPeriodTotalUserTime; LARGE_INTEGER ThisPeriodTotalKernelTime; DWORD TotalPageFaultCount; DWORD TotalProcesses; DWORD
// ActiveProcesses; DWORD TotalTerminatedProcesses;} JOBOBJECT_BASIC_ACCOUNTING_INFORMATION,
// *PJOBOBJECT_BASIC_ACCOUNTING_INFORMATION; https://msdn.microsoft.com/en-us/library/windows/desktop/ms684143(v=vs.85).aspx
[PInvokeData("WinNT.h", MSDNShortId = "ms684143")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_BASIC_ACCOUNTING_INFORMATION
{
///
/// The total amount of user-mode execution time for all active processes associated with the job, as well as all terminated
/// processes no longer associated with the job, in 100-nanosecond ticks.
///
public TimeSpan TotalUserTime;
///
/// The total amount of kernel-mode execution time for all active processes associated with the job, as well as all terminated
/// processes no longer associated with the job, in 100-nanosecond ticks.
///
public TimeSpan TotalKernelTime;
///
///
/// The total amount of user-mode execution time for all active processes associated with the job (as well as all terminated
/// processes no longer associated with the job) since the last call that set a per-job user-mode time limit, in 100-nanosecond ticks.
///
/// This member is set to 0 on creation of the job, and each time a per-job user-mode time limit is established.
///
public TimeSpan ThisPeriodTotalUserTime;
///
///
/// The total amount of kernel-mode execution time for all active processes associated with the job (as well as all terminated
/// processes no longer associated with the job) since the last call that set a per-job kernel-mode time limit, in 100-nanosecond ticks.
///
/// This member is set to zero on creation of the job, and each time a per-job kernel-mode time limit is established.
///
public TimeSpan ThisPeriodTotalKernelTime;
///
/// The total number of page faults encountered by all active processes associated with the job, as well as all terminated
/// processes no longer associated with the job.
///
public uint TotalPageFaultCount;
///
/// The total number of processes associated with the job during its lifetime, including those that have terminated. For example,
/// when a process is associated with a job, but the association fails because of a limit violation, this value is incremented.
///
public uint TotalProcesses;
///
/// The total number of processes currently associated with the job. When a process is associated with a job, but the association
/// fails because of a limit violation, this value is temporarily incremented. When the terminated process exits and all
/// references to the process are released, this value is decremented.
///
public uint ActiveProcesses;
/// The total number of processes terminated because of a limit violation.
public uint TotalTerminatedProcesses;
}
/// Contains basic accounting and I/O accounting information for a job object.
// typedef struct JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION { JOBOBJECT_BASIC_ACCOUNTING_INFORMATION BasicInfo; IO_COUNTERS
// IoInfo;} JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION, *PJOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION; https://msdn.microsoft.com/en-us/library/windows/desktop/ms684144(v=vs.85).aspx
[PInvokeData("WinNT.h", MSDNShortId = "ms684144")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION
{
///
/// A JOBOBJECT_BASIC_ACCOUNTING_INFORMATION structure that specifies the basic accounting information for the job.
///
public JOBOBJECT_BASIC_ACCOUNTING_INFORMATION BasicInfo;
///
/// An IO_COUNTERS structure that specifies the I/O accounting information for the job. The structure includes information
/// for all processes that have ever been associated with the job, in addition to the information for all processes currently
/// associated with the job.
///
public IO_COUNTERS IoInfo;
}
/// Contains basic limit information for a job object.
// typedef struct _JOBOBJECT_BASIC_LIMIT_INFORMATION { LARGE_INTEGER PerProcessUserTimeLimit; LARGE_INTEGER PerJobUserTimeLimit;
// DWORD LimitFlags; SIZE_T MinimumWorkingSetSize; SIZE_T MaximumWorkingSetSize; DWORD ActiveProcessLimit; ULONG_PTR Affinity; DWORD
// PriorityClass; DWORD SchedulingClass;} JOBOBJECT_BASIC_LIMIT_INFORMATION, *PJOBOBJECT_BASIC_LIMIT_INFORMATION; https://msdn.microsoft.com/en-us/library/windows/desktop/ms684147(v=vs.85).aspx
[PInvokeData("WinNT.h", MSDNShortId = "ms684147")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_BASIC_LIMIT_INFORMATION
{
///
///
/// If LimitFlags specifies JOB_OBJECT_LIMIT_PROCESS_TIME, this member is the per-process user-mode execution time
/// limit, in 100-nanosecond ticks. Otherwise, this member is ignored.
///
///
/// The system periodically checks to determine whether each process associated with the job has accumulated more user-mode time
/// than the set limit. If it has, the process is terminated.
///
/// If the job is nested, the effective limit is the most restrictive limit in the job chain.
///
public TimeSpan PerProcessUserTimeLimit;
///
///
/// If LimitFlags specifies JOB_OBJECT_LIMIT_JOB_TIME, this member is the per-job user-mode execution time limit,
/// in 100-nanosecond ticks. Otherwise, this member is ignored.
///
///
/// The system adds the current time of the processes associated with the job to this limit. For example, if you set this limit
/// to 1 minute, and the job has a process that has accumulated 5 minutes of user-mode time, the limit actually enforced is 6 minutes.
///
///
/// The system periodically checks to determine whether the sum of the user-mode execution time for all processes is greater than
/// this end-of-job limit. If it is, the action specified in the EndOfJobTimeAction member of the
/// JOBOBJECT_END_OF_JOB_TIME_INFORMATION structure is carried out. By default, all processes are terminated and the
/// status code is set to ERROR_NOT_ENOUGH_QUOTA.
///
///
/// To register for notification when this limit is exceeded without terminating processes, use the
/// SetInformationJobObject function with the JobObjectNotificationLimitInformation information class.
///
///
public TimeSpan PerJobUserTimeLimit;
///
///
/// The limit flags that are in effect. This member is a bitfield that determines whether other structure members are used. Any
/// combination of the following values can be specified.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_LIMIT_ACTIVE_PROCESS0x00000008
///
/// Establishes a maximum number of simultaneously active processes associated with the job. The ActiveProcessLimit member
/// contains additional information.
///
///
/// -
/// JOB_OBJECT_LIMIT_AFFINITY0x00000010
///
/// Causes all processes associated with the job to use the same processor affinity. The Affinity member contains additional
/// information.If the job is nested, the specified processor affinity must be a subset of the effective affinity of the parent
/// job. If the specified affinity a superset of the affinity of the parent job, it is ignored and the affinity of the parent job
/// is used.
///
///
/// -
/// JOB_OBJECT_LIMIT_BREAKAWAY_OK0x00000800
///
/// If any process associated with the job creates a child process using the CREATE_BREAKAWAY_FROM_JOB flag while this limit is
/// in effect, the child process is not associated with the job. This limit requires use of a
/// JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure. Its BasicLimitInformation member is a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
///
/// -
/// JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION0x00000400
///
/// Forces a call to the SetErrorMode function with the SEM_NOGPFAULTERRORBOX flag for each process associated with the job. If
/// an exception occurs and the system calls the UnhandledExceptionFilter function, the debugger will be given a chance to act.
/// If there is no debugger, the functions returns EXCEPTION_EXECUTE_HANDLER. Normally, this will cause termination of the
/// process with the exception code as the exit status. This limit requires use of a JOBOBJECT_EXTENDED_LIMIT_INFORMATION
/// structure. Its BasicLimitInformation member is a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
///
/// -
/// JOB_OBJECT_LIMIT_JOB_MEMORY0x00000200
///
/// Causes all processes associated with the job to limit the job-wide sum of their committed memory. When a process attempts to
/// commit memory that would exceed the job-wide limit, it fails. If the job object is associated with a completion port, a
/// JOB_OBJECT_MSG_JOB_MEMORY_LIMIT message is sent to the completion port. This limit requires use of a
/// JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure. Its BasicLimitInformation member is a JOBOBJECT_BASIC_LIMIT_INFORMATION
/// structure. To register for notification when this limit is exceeded while allowing processes to continue to commit memory,
/// use the SetInformationJobObject function with the JobObjectNotificationLimitInformation information class.
///
///
/// -
/// JOB_OBJECT_LIMIT_JOB_TIME0x00000004
///
/// Establishes a user-mode execution time limit for the job. The PerJobUserTimeLimit member contains additional information.
/// This flag cannot be used with JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME.
///
///
/// -
/// JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE0x00002000
///
/// Causes all processes associated with the job to terminate when the last handle to the job is closed.This limit requires use
/// of a JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure. Its BasicLimitInformation member is a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
///
/// -
/// JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME0x00000040
///
/// Preserves any job time limits you previously set. As long as this flag is set, you can establish a per-job time limit once,
/// then alter other limits in subsequent calls. This flag cannot be used with JOB_OBJECT_LIMIT_JOB_TIME.
///
///
/// -
/// JOB_OBJECT_LIMIT_PRIORITY_CLASS0x00000020
///
/// Causes all processes associated with the job to use the same priority class. For more information, see Scheduling Priorities.
/// The PriorityClass member contains additional information.If the job is nested, the effective priority class is the lowest
/// priority class in the job chain.
///
///
/// -
/// JOB_OBJECT_LIMIT_PROCESS_MEMORY0x00000100
///
/// Causes all processes associated with the job to limit their committed memory. When a process attempts to commit memory that
/// would exceed the per-process limit, it fails. If the job object is associated with a completion port, a
/// JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT message is sent to the completion port.If the job is nested, the effective memory limit
/// is the most restrictive memory limit in the job chain.This limit requires use of a JOBOBJECT_EXTENDED_LIMIT_INFORMATION
/// structure. Its BasicLimitInformation member is a JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
///
/// -
/// JOB_OBJECT_LIMIT_PROCESS_TIME0x00000002
///
/// Establishes a user-mode execution time limit for each currently active process and for all future processes associated with
/// the job. The PerProcessUserTimeLimit member contains additional information.
///
///
/// -
/// JOB_OBJECT_LIMIT_SCHEDULING_CLASS0x00000080
///
/// Causes all processes in the job to use the same scheduling class. The SchedulingClass member contains additional
/// information.If the job is nested, the effective scheduling class is the lowest scheduling class in the job chain.
///
///
/// -
/// JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK0x00001000
///
/// Allows any process associated with the job to create child processes that are not associated with the job. If the job is
/// nested and its immediate job object allows breakaway, the child process breaks away from the immediate job object and from
/// each job in the parent job chain, moving up the hierarchy until it reaches a job that does not permit breakaway. If the
/// immediate job object does not allow breakaway, the child process does not break away even if jobs in its parent job chain
/// allow it.This limit requires use of a JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure. Its BasicLimitInformation member is a
/// JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
///
/// -
/// JOB_OBJECT_LIMIT_SUBSET_AFFINITY0x00004000
///
/// Allows processes to use a subset of the processor affinity for all processes associated with the job. This value must be
/// combined with JOB_OBJECT_LIMIT_AFFINITY. Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is
/// supported starting with Windows 7 and Windows Server 2008 R2.
///
///
/// -
/// JOB_OBJECT_LIMIT_WORKINGSET0x00000001
///
/// Causes all processes associated with the job to use the same minimum and maximum working set sizes. The MinimumWorkingSetSize
/// and MaximumWorkingSetSize members contain additional information.If the job is nested, the effective working set size is the
/// smallest working set size in the job chain.
///
///
///
///
///
public JOBOBJECT_LIMIT_FLAGS LimitFlags;
///
///
/// If LimitFlags specifies JOB_OBJECT_LIMIT_WORKINGSET, this member is the minimum working set size in bytes for
/// each process associated with the job. Otherwise, this member is ignored.
///
/// If MaximumWorkingSetSize is nonzero, MinimumWorkingSetSize cannot be zero.
///
public SizeT MinimumWorkingSetSize;
///
///
/// If LimitFlags specifies JOB_OBJECT_LIMIT_WORKINGSET, this member is the maximum working set size in bytes for
/// each process associated with the job. Otherwise, this member is ignored.
///
/// If MinimumWorkingSetSize is nonzero, MaximumWorkingSetSize cannot be zero.
///
public SizeT MaximumWorkingSetSize;
///
///
/// If LimitFlags specifies JOB_OBJECT_LIMIT_ACTIVE_PROCESS, this member is the active process limit for the job.
/// Otherwise, this member is ignored.
///
///
/// If you try to associate a process with a job, and this causes the active process count to exceed this limit, the process is
/// terminated and the association fails.
///
///
public uint ActiveProcessLimit;
///
///
/// If LimitFlags specifies JOB_OBJECT_LIMIT_AFFINITY, this member is the processor affinity for all processes
/// associated with the job. Otherwise, this member is ignored.
///
///
/// The affinity must be a subset of the system affinity mask obtained by calling the GetProcessAffinityMask function. The
/// affinity of each thread is set to this value, but threads are free to subsequently set their affinity, as long as it is a
/// subset of the specified affinity mask. Processes cannot set their own affinity mask.
///
///
public UIntPtr Affinity;
///
///
/// If LimitFlags specifies JOB_OBJECT_LIMIT_PRIORITY_CLASS, this member is the priority class for all processes
/// associated with the job. Otherwise, this member is ignored.
///
///
/// Processes and threads cannot modify their priority class. The calling process must enable the
/// SE_INC_BASE_PRIORITY_NAME privilege.
///
///
public uint PriorityClass;
///
///
/// If LimitFlags specifies JOB_OBJECT_LIMIT_SCHEDULING_CLASS, this member is the scheduling class for all
/// processes associated with the job. Otherwise, this member is ignored.
///
///
/// The valid values are 0 to 9. Use 0 for the least favorable scheduling class relative to other threads, and 9 for the most
/// favorable scheduling class relative to other threads. By default, this value is 5. To use a scheduling class greater than 5,
/// the calling process must enable the SE_INC_BASE_PRIORITY_NAME privilege.
///
///
public uint SchedulingClass;
}
///
/// Contains the process identifier list for a job object. If the job is nested, the process identifier list consists of all
/// processes associated with the job and its child jobs.
///
// typedef struct _JOBOBJECT_BASIC_PROCESS_ID_LIST { DWORD NumberOfAssignedProcesses; DWORD NumberOfProcessIdsInList; ULONG_PTR
// ProcessIdList[1];} JOBOBJECT_BASIC_PROCESS_ID_LIST, *PJOBOBJECT_BASIC_PROCESS_ID_LIST; https://msdn.microsoft.com/en-us/library/windows/desktop/ms684150(v=vs.85).aspx
[PInvokeData("WinNT.h", MSDNShortId = "ms684150")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_BASIC_PROCESS_ID_LIST
{
/// The number of process identifiers to be stored in ProcessIdList.
public uint NumberOfAssignedProcesses;
///
/// The number of process identifiers returned in the ProcessIdList buffer. If this number is less than
/// NumberOfAssignedProcesses, increase the size of the buffer to accommodate the complete list.
///
public uint NumberOfProcessIdsInList;
///
/// A variable-length array of process identifiers returned by this call. Array elements 0 through
/// NumberOfProcessIdsInList – 1 contain valid process identifiers.
///
public IntPtr ProcessIdList;
}
/// Contains basic user-interface restrictions for a job object.
// typedef struct _JOBOBJECT_BASIC_UI_RESTRICTIONS { DWORD UIRestrictionsClass;} JOBOBJECT_BASIC_UI_RESTRICTIONS,
// *PJOBOBJECT_BASIC_UI_RESTRICTIONS; https://msdn.microsoft.com/en-us/library/windows/desktop/ms684152(v=vs.85).aspx
[PInvokeData("WinNT.h", MSDNShortId = "ms684152")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_BASIC_UI_RESTRICTIONS
{
///
/// The restriction class for the user interface. This member can be one or more of the following values.
///
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_UILIMIT_DESKTOP0x00000040
///
/// Prevents processes associated with the job from creating desktops and switching desktops using the CreateDesktop and
/// SwitchDesktop functions.
///
///
/// -
/// JOB_OBJECT_UILIMIT_DISPLAYSETTINGS0x00000010
/// Prevents processes associated with the job from calling the ChangeDisplaySettings function.
///
/// -
/// JOB_OBJECT_UILIMIT_EXITWINDOWS0x00000080
/// Prevents processes associated with the job from calling the ExitWindows or ExitWindowsEx function.
///
/// -
/// JOB_OBJECT_UILIMIT_GLOBALATOMS0x00000020
///
/// Prevents processes associated with the job from accessing global atoms. When this flag is used, each job has its own atom table.
///
///
/// -
/// JOB_OBJECT_UILIMIT_HANDLES0x00000001
///
/// Prevents processes associated with the job from using USER handles owned by processes not associated with the same job.
///
///
/// -
/// JOB_OBJECT_UILIMIT_READCLIPBOARD0x00000002
/// Prevents processes associated with the job from reading data from the clipboard.
///
/// -
/// JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS0x00000008
/// Prevents processes associated with the job from changing system parameters by using the SystemParametersInfo function.
///
/// -
/// JOB_OBJECT_UILIMIT_WRITECLIPBOARD0x00000004
/// Prevents processes associated with the job from writing data to the clipboard.
///
///
///
///
public JOBOBJECT_UILIMIT_FLAGS UIRestrictionsClass;
}
///
/// Contains CPU rate control information for a job object. This structure is used by the SetInformationJobObject and
/// QueryInformationJobObject functions with the JobObjectCpuRateControlInformation information class.
///
///
///
/// You can set CPU rate control for multiple jobs in a hierarchy of nested jobs. When you set CPU rate control for a job object, the
/// settings apply to the job and its child jobs in the hierarchy. When you set CPU rate control for a job in a nested hierarchy, the
/// system calculates the corresponding quotas with respect to the CPU rate control of the immediate parent job for the job. In other
/// words, the rates set for the job represent its portion of the CPU rate that is allocated to its parent job. If a job object does
/// not have a parent with CPU rate control turned on in the chain of its parent jobs, the rate control for the job represents the
/// portion of the CPU for the entire system.
///
///
/// CPU rate control cannot be used by job objects in applications running under Remote Desktop Services (formerly Terminal Services)
/// if Dynamic Fair Share Scheduling (DFSS) is in effect.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_cpu_rate_control_information typedef struct
// _JOBOBJECT_CPU_RATE_CONTROL_INFORMATION { DWORD ControlFlags; union { DWORD CpuRate; DWORD Weight; struct { WORD MinRate; WORD
// MaxRate; } DUMMYSTRUCTNAME; } DUMMYUNIONNAME; } JOBOBJECT_CPU_RATE_CONTROL_INFORMATION, *PJOBOBJECT_CPU_RATE_CONTROL_INFORMATION;
[PInvokeData("winnt.h", MSDNShortId = "eaa5bda2-a37e-441b-a0e4-e00dff6425b2")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_CPU_RATE_CONTROL_INFORMATION
{
///
/// The scheduling policy for CPU rate control. This member can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_CPU_RATE_CONTROL_ENABLE 0x1
///
/// This flag enables the job's CPU rate to be controlled based on weight or hard cap. You must set this value if you also set
/// JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED, JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP, or JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE.
///
///
/// -
/// JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED 0x2
///
/// The job's CPU rate is calculated based on its relative weight to the weight of other jobs. If this flag is set, the Weight
/// member contains more information. If this flag is clear, the CpuRate member contains more information. If you set
/// JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED, you cannot also set JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE.
///
///
/// -
/// JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP 0x4
///
/// The job's CPU rate is a hard limit. After the job reaches its CPU cycle limit for the current scheduling interval, no threads
/// associated with the job will run until the next interval. If you set JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP, you cannot also
/// set JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE.
///
///
/// -
/// JOB_OBJECT_CPU_RATE_CONTROL_NOTIFY 0x8
/// Sends messages when the CPU rate for the job exceeds the rate limits for the job during the tolerance interval.
///
/// -
/// JOB_OBJECT_ CPU_RATE_CONTROL_MIN_MAX_RATE 0x10
///
/// The CPU rate for the job is limited by minimum and maximum rates that you specify in the MinRate and MaxRate members. If you
/// set JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE, you can set neither JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED nor JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP.
///
///
///
///
public JOB_OBJECT_CPU_RATE_CONTROL_FLAGS ControlFlags;
/// Value based on which ControlFlags value is set.
public CPU_RATE_CONTROL_UNION Union;
/// Value based on which ControlFlags value is set.
[StructLayout(LayoutKind.Explicit)]
public struct CPU_RATE_CONTROL_UNION
{
///
///
/// Specifies the portion of processor cycles that the threads in a job object can use during each scheduling interval, as
/// the number of cycles per 10,000 cycles. If the ControlFlags member specifies
/// JOB_OBJECT_CPU_RATE_WEIGHT_BASED or JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE, this member is not used.
///
///
/// Set CpuRate to a percentage times 100. For example, to let the job use 20% of the CPU, set CpuRate to 20
/// times 100, or 2,000.
///
/// Do not set CpuRate to 0. If CpuRate is 0, SetInformationJobObject returns INVALID_ARGS.
///
[FieldOffset(0)]
public uint CpuRate;
///
///
/// If the ControlFlags member specifies JOB_OBJECT_CPU_RATE_WEIGHT_BASED, this member specifies the scheduling
/// weight of the job object, which determines the share of processor time given to the job relative to other workloads on
/// the processor.
///
///
/// This member can be a value from 1 through 9, where 1 is the smallest share and 9 is the largest share. The default is 5,
/// which should be used for most workloads.
///
///
/// If the ControlFlags member specifies JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE, this member is not used.
///
///
[FieldOffset(0)]
public uint Weight;
///
///
/// Specifies the minimum portion of the processor cycles that the threads in a job object can reserve during each scheduling
/// interval. Specify this rate as a percentage times 100. For example, to set a minimum rate of 50%, specify 50 times 100,
/// or 5,000.
///
///
/// For the minimum rates to work correctly, the sum of the minimum rates for all of the job objects in the system cannot
/// exceed 10,000, which is the equivalent of 100%.
///
///
[FieldOffset(0)]
public ushort MinRate;
///
///
/// Specifies the maximum portion of processor cycles that the threads in a job object can use during each scheduling
/// interval. Specify this rate as a percentage times 100. For example, to set a maximum rate of 50%, specify 50 times 100,
/// or 5,000.
///
///
/// After the job reaches this limit for a scheduling interval, no threads associated with the job can run until the next
/// scheduling interval.
///
///
[FieldOffset(2)]
public ushort MaxRate;
}
}
/// Specifies the action the system will perform when an end-of-job time limit is exceeded.
// typedef struct _JOBOBJECT_END_OF_JOB_TIME_INFORMATION { DWORD EndOfJobTimeAction;} JOBOBJECT_END_OF_JOB_TIME_INFORMATION,
// PJOBOBJECT_END_OF_JOB_TIME_INFORMATION; https://msdn.microsoft.com/en-us/library/windows/desktop/ms684155(v=vs.85).aspx
[PInvokeData("WinNT.h", MSDNShortId = "ms684155")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_END_OF_JOB_TIME_INFORMATION
{
///
///
/// The action that the system will perform when the end-of-job time limit has been exceeded. This member can be one of the
/// following values.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_TERMINATE_AT_END_OF_JOB0
///
/// Terminates all processes and sets the exit status to ERROR_NOT_ENOUGH_QUOTA. The processes cannot prevent or delay their own
/// termination. The job object is set to the signaled state and remains signaled until this limit is reset. No additional
/// processes can be assigned to the job until the limit is reset. This is the default termination action.
///
///
/// -
/// JOB_OBJECT_POST_AT_END_OF_JOB1
///
/// Posts a completion packet to the completion port using the PostQueuedCompletionStatus function. After the completion packet
/// is posted, the system clears the end-of-job time limit, and processes in the job can continue their execution. If no
/// completion port is associated with the job when the time limit has been exceeded, the action taken is the same as for JOB_OBJECT_TERMINATE_AT_END_OF_JOB.
///
///
///
///
///
public JOBOBJECT_END_OF_JOB_TIME_ACTION EndOfJobTimeAction;
}
/// Contains basic and extended limit information for a job object.
// typedef struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION { JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation; IO_COUNTERS
// IoInfo; SIZE_T ProcessMemoryLimit; SIZE_T JobMemoryLimit; SIZE_T PeakProcessMemoryUsed; SIZE_T PeakJobMemoryUsed;}
// JOBOBJECT_EXTENDED_LIMIT_INFORMATION, *PJOBOBJECT_EXTENDED_LIMIT_INFORMATION; https://msdn.microsoft.com/en-us/library/windows/desktop/ms684156(v=vs.85).aspx
[PInvokeData("WinNT.h", MSDNShortId = "ms684156")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_EXTENDED_LIMIT_INFORMATION
{
/// A JOBOBJECT_BASIC_LIMIT_INFORMATION structure that contains basic limit information.
public JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation;
/// Reserved.
public IO_COUNTERS IoInfo;
///
/// If the LimitFlags member of the JOBOBJECT_BASIC_LIMIT_INFORMATION structure specifies the
/// JOB_OBJECT_LIMIT_PROCESS_MEMORY value, this member specifies the limit for the virtual memory that can be committed by
/// a process. Otherwise, this member is ignored.
///
public SizeT ProcessMemoryLimit;
///
/// If the LimitFlags member of the JOBOBJECT_BASIC_LIMIT_INFORMATION structure specifies the
/// JOB_OBJECT_LIMIT_JOB_MEMORY value, this member specifies the limit for the virtual memory that can be committed for
/// the job. Otherwise, this member is ignored.
///
public SizeT JobMemoryLimit;
/// The peak memory used by any process ever associated with the job.
public SizeT PeakProcessMemoryUsed;
/// The peak memory usage of all processes currently associated with the job.
public SizeT PeakJobMemoryUsed;
}
///
[PInvokeData("WinNT.h")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_IO_ATTRIBUTION_INFORMATION
{
///
public uint ControlFlags;
///
public JOBOBJECT_IO_ATTRIBUTION_STATS ReadStats;
///
public JOBOBJECT_IO_ATTRIBUTION_STATS WriteStats;
}
///
[PInvokeData("WinNT.h")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_IO_ATTRIBUTION_STATS
{
///
public UIntPtr IoCount;
///
public ulong TotalNonOverlappedQueueTime;
///
public ulong TotalNonOverlappedServiceTime;
///
public ulong TotalSize;
}
///
/// Contains information used to control the I/O rate for a job. This structure is used by the
/// SetIoRateControlInformationJobObject and QueryIoRateControlInformationJobObject functions.
///
// typedef struct JOBOBJECT_IO_RATE_CONTROL_INFORMATION { LONG64 MaxIops; LONG64 MaxBandwith; LONG64 ReservationIops; PWSTR
// VolumeName; ULONG BaseIoSize; ULONG ControlFlags;} JOBOBJECT_IO_RATE_CONTROL_INFORMATION; https://msdn.microsoft.com/en-us/library/windows/desktop/mt280122(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
[PInvokeData("Jobapi2.h", MSDNShortId = "mt280122")]
public struct JOBOBJECT_IO_RATE_CONTROL_INFORMATION
{
///
/// The maximum limit for the I/O rate in I/O operations per second (IOPS). Set to 0 if to specify no limit.
///
/// When you set both MaxIops and MaxBandwith, the operating system enforces the first limit that the I/O rate reaches.
///
///
public long MaxIops;
///
/// The maximum limit for the I/O rate in bytes per second. Set to 0 to specify no limit.
///
/// When you set both MaxBandwith and MaxIops, the operating system enforces the first limit that the I/O rate reaches.
///
///
public long MaxBandwidth;
///
///
/// Sets a minimum I/O rate which the operating system reserves for the job. To make no reservation for the job, set this value
/// to 0.
///
///
/// The operating system allows the job to perform I/O operations at this rate, if possible. If the sum of the minimum rates for
/// all jobs exceeds the capacity of the operating system, the rate at which the operating system allows each job to perform I/O
/// operations is proportional to the reservation for the job.
///
///
public long ReservationIops;
///
///
/// The NT device name for the volume to which you want to apply the policy for the I/O rate. For information about NT device
/// names, see NT Device Names.
///
///
/// If this member is NULL, the policy for the I/O rate applies to all of the volumes for the operating system. For
/// example, if this member is NULL and the MaxIops member is 100, the maximum limit for the I/O rate for each
/// volume is set to 100 IOPS, instead of setting an aggregate limit for the I/O rate across all volumes of 100 IOPS.
///
///
[MarshalAs(UnmanagedType.LPWStr)]
public string VolumeName;
///
///
/// The base size of the normalized I/O unit, in bytes. For example, if the BaseIoSize member is 8,000, every 8,000 bytes
/// counts as one I/O unit. 4,000 bytes is also one I/O unit in this example, while 8,001 bytes is two I/O units.
///
/// You can set the value of this base I/O size by using the StorageBaseIOSize value of the
/// HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Control\ QoS
/// The value of the BaseIoSize member is subject to the following constraints:
///
/// To query for the base size of the normalized I/O unit without creating a job, call
/// QueryIoRateControlInformationJobObject with the hJob parameter set to NULL from a process that is not
/// associated with a job.
///
///
public int BaseIoSize;
///
/// The policy for control of the I/O rate. This member can be one of the following values.
///
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_IO_RATE_CONTROL_ENABLE0x1
///
/// Turns on control of the I/O rate for the job when this structure is passed to the SetIoRateControlInformationJobObject
/// function. Indicates that control of the I/O rate for the job is turned on when this structure is used with the
/// QueryIoRateControlInformationJobObject function.
///
///
///
///
///
public JOB_OBJECT_IO_RATE_CONTROL_FLAGS ControlFlags;
}
///
[PInvokeData("WinNT.h")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct JOBOBJECT_IO_RATE_CONTROL_INFORMATION_NATIVE
{
///
public long MaxIops;
///
public long MaxBandwidth;
///
public long ReservationIops;
///
[MarshalAs(UnmanagedType.LPWStr)]
public string VolumeName;
///
public uint BaseIoSize;
///
public JOB_OBJECT_IO_RATE_CONTROL_FLAGS ControlFlags;
///
public ushort VolumeNameLength;
}
///
[PInvokeData("WinNT.h")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct JOBOBJECT_IO_RATE_CONTROL_INFORMATION_NATIVE_V2
{
///
public long MaxIops;
///
public long MaxBandwidth;
///
public long ReservationIops;
///
public string VolumeName;
///
public uint BaseIoSize;
///
public JOB_OBJECT_IO_RATE_CONTROL_FLAGS ControlFlags;
///
public ushort VolumeNameLength;
///
public long CriticalReservationIops;
///
public long ReservationBandwidth;
///
public long CriticalReservationBandwidth;
///
public long MaxTimePercent;
///
public long ReservationTimePercent;
///
public long CriticalReservationTimePercent;
}
///
[PInvokeData("WinNT.h")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct JOBOBJECT_IO_RATE_CONTROL_INFORMATION_NATIVE_V3
{
///
public long MaxIops;
///
public long MaxBandwidth;
///
public long ReservationIops;
///
public string VolumeName;
///
public uint BaseIoSize;
///
public JOB_OBJECT_IO_RATE_CONTROL_FLAGS ControlFlags;
///
public ushort VolumeNameLength;
///
public long CriticalReservationIops;
///
public long ReservationBandwidth;
///
public long CriticalReservationBandwidth;
///
public long MaxTimePercent;
///
public long ReservationTimePercent;
///
public long CriticalReservationTimePercent;
///
public long SoftMaxIops;
///
public long SoftMaxBandwidth;
///
public long SoftMaxTimePercent;
///
public long LimitExcessNotifyIops;
///
public long LimitExcessNotifyBandwidth;
///
public long LimitExcessNotifyTimePercent;
}
/// Undocumented.
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_JOBSET_INFORMATION
{
/// Undocumented.
public uint MemberLevel;
}
///
/// Contains information about resource notification limits that have been exceeded for a job object. This structure is used with the
/// QueryInformationJobObject function with the JobObjectLimitViolationInformation information class.
///
// typedef struct _JOBOBJECT_LIMIT_VIOLATION_INFORMATION { DWORD LimitFlags; DWORD ViolationLimitFlags; DWORD64 IoReadBytes; DWORD64
// IoReadBytesLimit; DWORD64 IoWriteBytes; DWORD64 IoWriteBytesLimit; LARGE_INTEGER PerJobUserTime; LARGE_INTEGER
// PerJobUserTimeLimit; DWORD64 JobMemory; DWORD64 JobMemoryLimit; JOBOBJECT_RATE_CONTROL_TOLERANCE RateControlTolerance;
// JOBOBJECT_RATE_CONTROL_TOLERANCE RateControlToleranceLimit;} JOBOBJECT_LIMIT_VIOLATION_INFORMATION,
// *PJOBOBJECT_LIMIT_VIOLATION_INFORMATION; https://msdn.microsoft.com/en-us/library/windows/desktop/hh448385(v=vs.85).aspx
[PInvokeData("WinNT.h", MSDNShortId = "hh448385")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_LIMIT_VIOLATION_INFORMATION
{
///
///
/// Flags that identify the notification limits in effect for the job. This member is a bitfield that determines whether other
/// structure members are used. This member can be any combination of the following values.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_LIMIT_JOB_MEMORY0x00000200
/// The job has a committed memory notification limit. The JobMemoryLimit member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_JOB_READ_BYTES0x00010000
/// The job has an I/O read bytes notification limit. The IoReadBytesLimit member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_JOB_TIME0x00000004
/// The job has a user-mode execution time notification limit. The PerJobUserTimeLimit member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_JOB_WRITE_BYTES0x00020000
/// The job has an I/O write bytes notification limit. The IoWriteBytesLimit member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_RATE_CONTROL0x00040000
///
/// The extent to which a job can exceed its CPU rate control limit. The RateControlToleranceLimit member contains more information.
///
///
///
///
///
public JOBOBJECT_LIMIT_FLAGS LimitFlags;
///
///
/// Flags that identify the notification limits that have been exceeded. This member is a bitfield that determines whether other
/// structure members are used. This member can be any combination of the following values.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_LIMIT_READ_BYTES0x00010000
/// The job's I/O read bytes notification limit has been exceeded. The IoReadBytes member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_WRITE_BYTES0x00020000
/// The job's I/O write bytes notification limit has been exceeded. The IoWriteBytes member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_JOB_TIME0x00000004
/// The job's user-mode execution time notification limit has been exceeded. The PerJobUserTime member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_JOB_MEMORY0x00000200
/// The job's committed memory notification limit has been exceeded. The JobMemory member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_RATE_CONTROL0x00040000
/// The job's CPU rate control limit has been exceeded. The RateControlTolerance member contains more information.
///
///
///
///
public JOBOBJECT_LIMIT_FLAGS ViolationLimitFlags;
///
/// If the ViolationLimitFlags member specifies JOB_OBJECT_LIMIT_READ_BYTES, this member contains the total I/O read bytes for
/// all processes in the job at the time the notification was sent.
///
public ulong IoReadBytes;
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_READ_BYTES, this member contains the I/O read bytes notification limit in
/// effect for the job.
///
public ulong IoReadBytesLimit;
///
/// If the ViolationLimitFlags member specifies JOB_OBJECT_LIMIT_WRITE_BYTES, this member contains the total I/O write bytes for
/// all processes in the job at the time the notification was sent.
///
public ulong IoWriteBytes;
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_WRITE_BYTES, this member contains the I/O write bytes notification limit
/// in effect for the job.
///
public ulong IoWriteBytesLimit;
///
/// If the ViolationLimitFlags member specifies JOB_OBJECT_LIMIT_JOB_TIME, this member contains the total user-mode execution
/// time for all processes in the job at the time the notification was sent.
///
public TimeSpan PerJobUserTime;
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_JOB_TIME, this member contains the user-mode execution notification limit
/// in effect for the job.
///
public TimeSpan PerJobUserTimeLimit;
///
/// If the ViolationLimitFlags member specifies JOB_OBJECT_LIMIT_JOB_MEMORY, this member contains the committed memory for all
/// processes in the job at the time the notification was sent.
///
public ulong JobMemory;
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_JOB_MEMORY, this member contains the committed memory limit in effect for
/// the job.
///
public ulong JobMemoryLimit;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_RATE_CONTROL, this member specifies the extent to which the job
/// exceeded its CPU rate control limits at the time the notification was sent. This member can be one of the following values.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceLow1
/// The job exceeded its CPU rate control limits for 20% of the tolerance interval.
///
/// -
/// ToleranceMedium2
/// The job exceeded its CPU rate control limits for 40% of the tolerance interval.
///
/// -
/// ToleranceHigh3
/// The job exceeded its CPU rate control limits for 60% of the tolerance interval.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE RateControlTolerance;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_RATE_CONTROL, this member contains the CPU rate control notification
/// limits specified for the job.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceIntervalShort1
/// The tolerance interval is 10 seconds.
///
/// -
/// ToleranceIntervalMedium2
/// The tolerance interval is one minute.
///
/// -
/// ToleranceIntervalLong3
/// The tolerance interval is 10 minutes.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE RateControlToleranceLimit;
}
///
/// Contains extended information about resource notification limits that have been exceeded for a job object. This structure is used
/// with the QueryInformationJobObject function with the JobObjectLimitViolationInformation2 information class.
///
// typedef struct JOBOBJECT_LIMIT_VIOLATION_INFORMATION_2 { DWORD LimitFlags; DWORD ViolationLimitFlags; DWORD64 IoReadBytes; DWORD64
// IoReadBytesLimit; DWORD64 IoWriteBytes; DWORD64 IoWriteBytesLimit; LARGE_INTEGER PerJobUserTime; LARGE_INTEGER
// PerJobUserTimeLimit; DWORD64 JobMemory; union { DWORD64 JobHighMemoryLimit; DWORD64 JobMemoryLimit; }; union {
// JOBOBJECT_RATE_CONTROL_TOLERANCE RateControlTolerance; JOBOBJECT_RATE_CONTROL_TOLERANCE CpuRateControlTolerance; }; union {
// JOBOBJECT_RATE_CONTROL_TOLERANCE RateControlToleranceLimit; JOBOBJECT_RATE_CONTROL_TOLERANCE CpuRateControlToleranceLimit; };
// DWORD64 JobLowMemoryLimit; JOBOBJECT_RATE_CONTROL_TOLERANCE IoRateControlTolerance; JOBOBJECT_RATE_CONTROL_TOLERANCE
// IoRateControlToleranceLimit; JOBOBJECT_RATE_CONTROL_TOLERANCE NetRateControlTolerance; JOBOBJECT_RATE_CONTROL_TOLERANCE
// NetRateControlToleranceLimit;} JOBOBJECT_LIMIT_VIOLATION_INFORMATION_2; https://msdn.microsoft.com/en-us/library/windows/desktop/mt280123(v=vs.85).aspx
[PInvokeData("Winnt.h", MSDNShortId = "mt280123")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_LIMIT_VIOLATION_INFORMATION_2
{
///
///
/// Flags that identify the notification limits in effect for the job. This member is a bitfield that determines whether other
/// structure members are used. This member can be any combination of the following values.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_LIMIT_JOB_MEMORY0x00000200
/// The job has a committed memory notification limit. The JobMemoryLimit member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_JOB_READ_BYTES0x00010000
/// The job has an I/O read bytes notification limit. The IoReadBytesLimit member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_JOB_TIME0x00000004
/// The job has a user-mode execution time notification limit. The PerJobUserTimeLimit member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_JOB_WRITE_BYTES0x00020000
/// The job has an I/O write bytes notification limit. The IoWriteBytesLimit member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_RATE_CONTROL0x00040000
///
/// The extent to which a job can exceed its CPU rate control limit. The RateControlToleranceLimit member contains more information.
///
///
///
///
///
public JOBOBJECT_LIMIT_FLAGS LimitFlags;
///
///
/// Flags that identify the notification limits that have been exceeded. This member is a bitfield that determines whether other
/// structure members are used. This member can be any combination of the following values.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_LIMIT_READ_BYTES0x00010000
/// The job's I/O read bytes notification limit has been exceeded. The IoReadBytes member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_WRITE_BYTES0x00020000
/// The job's I/O write bytes notification limit has been exceeded. The IoWriteBytes member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_JOB_TIME0x00000004
/// The job's user-mode execution time notification limit has been exceeded. The PerJobUserTime member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_JOB_MEMORY0x00000200
/// The job's committed memory notification limit has been exceeded. The JobMemory member contains more information.
///
/// -
/// JOB_OBJECT_LIMIT_RATE_CONTROL0x00040000
/// The job's CPU rate control limit has been exceeded. The RateControlTolerance member contains more information.
///
///
///
///
public JOBOBJECT_LIMIT_FLAGS ViolationLimitFlags;
///
/// If the ViolationLimitFlags member specifies JOB_OBJECT_LIMIT_READ_BYTES, this member contains the total I/O read bytes for
/// all processes in the job at the time the notification was sent.
///
public ulong IoReadBytes;
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_READ_BYTES, this member contains the I/O read bytes notification limit in
/// effect for the job.
///
public ulong IoReadBytesLimit;
///
/// If the ViolationLimitFlags member specifies JOB_OBJECT_LIMIT_WRITE_BYTES, this member contains the total I/O write bytes for
/// all processes in the job at the time the notification was sent.
///
public ulong IoWriteBytes;
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_WRITE_BYTES, this member contains the I/O write bytes notification limit
/// in effect for the job.
///
public ulong IoWriteBytesLimit;
///
/// If the ViolationLimitFlags member specifies JOB_OBJECT_LIMIT_JOB_TIME, this member contains the total user-mode execution
/// time for all processes in the job at the time the notification was sent.
///
public TimeSpan PerJobUserTime;
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_JOB_TIME, this member contains the user-mode execution notification limit
/// in effect for the job.
///
public TimeSpan PerJobUserTimeLimit;
///
/// If the ViolationLimitFlags member specifies JOB_OBJECT_LIMIT_JOB_MEMORY, this member contains the committed memory for all
/// processes in the job at the time the notification was sent.
///
public ulong JobMemory;
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_JOB_MEMORY, this member contains the committed memory limit in effect for
/// the job.
///
public ulong JobMemoryLimit;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_RATE_CONTROL, this member specifies the extent to which the job
/// exceeded its CPU rate control limits at the time the notification was sent. This member can be one of the following values.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceLow1
/// The job exceeded its CPU rate control limits for 20% of the tolerance interval.
///
/// -
/// ToleranceMedium2
/// The job exceeded its CPU rate control limits for 40% of the tolerance interval.
///
/// -
/// ToleranceHigh3
/// The job exceeded its CPU rate control limits for 60% of the tolerance interval.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE RateControlTolerance;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_RATE_CONTROL, this member contains the CPU rate control notification
/// limits specified for the job.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceIntervalShort1
/// The tolerance interval is 10 seconds.
///
/// -
/// ToleranceIntervalMedium2
/// The tolerance interval is one minute.
///
/// -
/// ToleranceIntervalLong3
/// The tolerance interval is 10 minutes.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE RateControlToleranceLimit;
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_JOB_MEMORY_LOW, this member contains the committed minimum
/// memory limit in effect for the job.
///
public ulong JobLowMemoryLimit;
///
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_IO_RATE_CONTROL, this member specifies the extent to which
/// the job exceeded its I/O rate control limits at the time the notification was sent. This member can be one of the following values.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceLow1
/// The job exceeded its I/O rate control limits for 20% of the tolerance interval.
///
/// -
/// ToleranceMedium2
/// The job exceeded its I/O rate control limits for 40% of the tolerance interval.
///
/// -
/// ToleranceHigh3
/// The job exceeded its I/O rate control limits for 60% of the tolerance interval.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE IoRateControlTolerance;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_IO_RATE_CONTROL, this member contains the I/O rate control
/// notification limits specified for the job.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceLow1
/// The job can exceed its I/O rate control limits for 20% of the tolerance interval.
///
/// -
/// ToleranceMedium2
/// The job can exceed its I/O rate control limits for 40% of the tolerance interval.
///
/// -
/// ToleranceHigh3
/// The job can exceed its I/O rate control limits for 60% of the tolerance interval.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE IoRateControlToleranceLimit;
///
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_NET_RATE_CONTROL, this member specifies the extent to which
/// the job exceeded its network rate control limits at the time the notification was sent. This member can be one of the
/// following values.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceLow1
/// The job exceeded its network rate control limits for 20% of the tolerance interval.
///
/// -
/// ToleranceMedium2
/// The job exceeded its network rate control limits for 40% of the tolerance interval.
///
/// -
/// ToleranceHigh3
/// The job exceeded its network rate control limits for 60% of the tolerance interval.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE NetRateControlTolerance;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_NETWORK_RATE_CONTROL, this member contains the network rate
/// control notification limits specified for the job.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceLow1
/// The job can exceed its network rate control limits for 20% of the tolerance interval.
///
/// -
/// ToleranceMedium2
/// The job can exceed its network rate control limits for 40% of the tolerance interval.
///
/// -
/// ToleranceHigh3
/// The job can exceed its network rate control limits for 60% of the tolerance interval.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE NetRateControlToleranceLimit;
}
///
/// Contains information used to control the network traffic for a job. This structure is used by the SetInformationJobObject
/// and QueryInformationJobObject functions with the JobObjectNetRateControlInformation information class.
///
// typedef struct JOBOBJECT_NET_RATE_CONTROL_INFORMATION { DWORD64 MaxBandwidth; JOB_OBJECT_NET_RATE_CONTROL_FLAGS ControlFlags; BYTE
// DscpTag;} JOBOBJECT_NET_RATE_CONTROL_INFORMATION; https://msdn.microsoft.com/en-us/library/windows/desktop/mt280124(v=vs.85).aspx
[PInvokeData("Winnt.h", MSDNShortId = "mt280124")]
[StructLayout(LayoutKind.Sequential, Pack = 4, Size = 16)]
public struct JOBOBJECT_NET_RATE_CONTROL_INFORMATION
{
/// The maximum bandwidth for outgoing network traffic for the job, in bytes.
public ulong MaxBandwidth;
///
/// A combination of JOB_OBJECT_NET_RATE_CONTROL_FLAGS enumeration values that specify the scheduling policy for network
/// rate control.
///
public JOB_OBJECT_NET_RATE_CONTROL_FLAGS ControlFlags;
///
/// The value to use for the Differentiated Service code point (DSCP) field to turn on network quality of service (QoS) for all
/// outgoing network traffic generated by the processes of the job object. The valid range is from 0x00 through 0x3F. For
/// information about DSCP, see Differentiated Services.
///
public byte DscpTag;
}
///
/// Contains information about notification limits for a job object. This structure is used by the SetInformationJobObject and
/// QueryInformationJobObject functions with the JobObjectNotificationLimitInformation information class.
///
// typedef struct _JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION { DWORD64 IoReadBytesLimit; DWORD64 IoWriteBytesLimit; LARGE_INTEGER
// PerJobUserTimeLimit; DWORD64 JobMemoryLimit; JOBOBJECT_RATE_CONTROL_TOLERANCE RateControlTolerance;
// JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL RateControlToleranceInterval; DWORD LimitFlags;}
// JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION, *PJOBOBJECT_NOTIFICATION_LIMIT_INFORMATION; https://msdn.microsoft.com/en-us/library/windows/desktop/hh448386(v=vs.85).aspx
[PInvokeData("WinNT.h", MSDNShortId = "hh448386")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION
{
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_FLAGS_READ_BYTES, this member is the notification limit for total I/O
/// bytes read by all processes in the job. Otherwise, this member is ignored.
///
public ulong IoReadBytesLimit;
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_FLAGS_WRITE_BYTES, this member is the notification limit for total I/O
/// bytes written by all processes in the job. Otherwise, this member is ignored.
///
public ulong IoWriteBytesLimit;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_JOB_TIME, this member is the notification limit for per-job user-mode
/// execution time, in 100-nanosecond ticks. Otherwise, this member is ignored.
///
///
/// The system adds the accumulated execution time of processes associated with the job to this limit when the limit is set. For
/// example, if a process associated with the job has already accumulated 5 minutes of user-mode execution time and the limit is
/// set to 1 minute, the limit actually enforced is 6 minutes.
///
///
/// To specify PerJobUserTimeLimit as an enforceable limit and terminate processes in jobs that exceed the limit, see the
/// JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
///
public TimeSpan PerJobUserTimeLimit;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_JOB_MEMORY, this member is the notification limit for total virtual
/// memory that can be committed by all processes in the job, in bytes. Otherwise, this member is ignored.
///
///
/// To specify JobMemoryLimit as an enforceable limit and prevent processes in jobs that exceed the limit from continuing
/// to commit memory, see the JOBOBJECT_EXTENDED_LIMIT_INFORMATION structure.
///
///
public ulong JobMemoryLimit;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_RATE_CONTROL, this member specifies the extent to which a job can
/// exceed its CPU rate control limits during the interval specified by the RateControlToleranceInterval member.
/// Otherwise, this member is ignored.
///
/// This member can be one of the following values. If no value is specified, ToleranceHigh is used.
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceLow1
/// The job can exceed its CPU rate control limits for 20% of the tolerance interval.
///
/// -
/// ToleranceMedium2
/// The job can exceed its CPU rate control limits for 40% of the tolerance interval.
///
/// -
/// ToleranceHigh3
/// The job can exceed its CPU rate control limits for 60% of the tolerance interval.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE RateControlTolerance;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_RATE_CONTROL, this member specifies the interval during which a job's
/// CPU usage is monitored to determine whether the job has exceeded its CPU rate control limits. Otherwise, this member is ignored.
///
/// This member can be one of the following values. If no value is specified, ToleranceIntervalShort is used.
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceIntervalShort1
/// The tolerance interval is 10 seconds.
///
/// -
/// ToleranceIntervalMedium2
/// The tolerance interval is one minute.
///
/// -
/// ToleranceIntervalLong3
/// The tolerance interval is 10 minutes.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL RateControlToleranceInterval;
///
///
/// The limit flags that are in effect. This member is a bitfield that determines whether other structure members are used. Any
/// combination of the following values can be specified.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_LIMIT_JOB_MEMORY0x00000200
///
/// Establishes the committed memory limit to the job-wide sum of committed memory for all processes associated with the job. The
/// JobMemoryLimit member contains additional information.
///
///
/// -
/// JOB_OBJECT_LIMIT_JOB_READ_BYTES0x00010000
///
/// Establishes the I/O read bytes limit to the job-wide sum of I/O bytes read by all processes associated with the job. The
/// IoReadBytesLimit member contains more information.
///
///
/// -
/// JOB_OBJECT_LIMIT_JOB_WRITE_BYTES0x00020000
///
/// Establishes the I/O write bytes limit to the job-wide sum of I/O bytes written by all processes associated with the job. The
/// IoWriteBytesLimit member contains more information.
///
///
/// -
/// JOB_OBJECT_LIMIT_JOB_TIME0x00000004
///
/// Establishes the limit for user-mode execution time for the job. The PerJobUserTimeLimit member contains additional information.
///
///
/// -
/// JOB_OBJECT_LIMIT_RATE_CONTROL0x00040000
///
/// Establishes the notification threshold for the CPU rate control limits established for the job. The RateControlTolerance and
/// RateControlToleranceInterval members contain additional information.CPU rate control limits are established by calling
/// SetInformationJobObject with the JobObjectCpuRateInformationClass information class.
///
///
///
///
///
public JOBOBJECT_LIMIT_FLAGS LimitFlags;
}
///
/// Contains extended information about notification limits for a job object. This structure is used by the
/// SetInformationJobObject and QueryInformationJobObject functions with the
/// JobObjectNotificationLimitInformation2 information class.
///
// typedef struct JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION_2 { DWORD64 IoReadBytesLimit; DWORD64 IoWriteBytesLimit; LARGE_INTEGER
// PerJobUserTimeLimit; union { DWORD64 JobHighMemoryLimit; DWORD64 JobMemoryLimit; }; union { JOBOBJECT_RATE_CONTROL_TOLERANCE
// RateControlTolerance; JOBOBJECT_RATE_CONTROL_TOLERANCE CpuRateControlTolerance; }; union {
// JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL RateControlToleranceInterval; JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL
// CpuRateControlToleranceInterval; }; DWORD LimitFlags; JOBOBJECT_RATE_CONTROL_TOLERANCE IoRateControlTolerance; DWORD64
// JobLowMemoryLimit; JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL IoRateControlToleranceInterval; JOBOBJECT_RATE_CONTROL_TOLERANCE
// NetRateControlTolerance; JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL NetRateControlToleranceInterval;}
// JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION_2; https://msdn.microsoft.com/en-us/library/windows/desktop/mt280125(v=vs.85).aspx
[PInvokeData("Winnt.h", MSDNShortId = "mt280125")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION_2
{
///
/// If the LimitFlags member specifies JOB_OBJECT_LIMIT_JOB_READ_BYTES, this member is the notification limit for the
/// total I/O bytes read by all processes in the job. Otherwise, this member is ignored.
///
public ulong IoReadBytesLimit;
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_JOB_WRITE_BYTES, this member is the notification limit for the
/// total I/O bytes written by all processes in the job. Otherwise, this member is ignored.
///
public ulong IoWriteBytesLimit;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_JOB_TIME, this member is the notification limit for per-job
/// user-mode execution time, in 100-nanosecond ticks. Otherwise, this member is ignored.
///
///
/// The system adds the accumulated execution time of processes associated with the job to this limit when the limit is set. For
/// example, if a process associated with the job has already accumulated 5 minutes of user-mode execution time and the limit is
/// set to 1 minute, the limit actually enforced is 6 minutes.
///
///
/// To specify PerJobUserTimeLimit as an enforceable limit and terminate processes in jobs that exceed the limit, see the
/// JOBOBJECT_BASIC_LIMIT_INFORMATION structure.
///
///
public TimeSpan PerJobUserTimeLimit;
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_JOB_MEMORY_HIGH, this member is the notification maximum limit
/// for total virtual memory that can be committed by all processes in the job, in bytes. Otherwise, this member is ignored.
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_JOB_MEMORY, this member is the notification maximum limit for
/// total virtual memory that can be committed by all processes in the job, in bytes. Otherwise, this member is ignored.
///
///
public ulong JobMemoryLimit;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_RATE_CONTROL, this member specifies the extent to which a job
/// can exceed its CPU rate control limits during the interval specified by the RateControlToleranceInterval member.
/// Otherwise, this member is ignored.
///
/// This member can be one of the following values. If no value is specified, ToleranceHigh is used.
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceLow1
/// The job can exceed its CPU rate control limits for 20% of the tolerance interval.
///
/// -
/// ToleranceMedium2
/// The job can exceed its CPU rate control limits for 40% of the tolerance interval.
///
/// -
/// ToleranceHigh3
/// The job can exceed its CPU rate control limits for 60% of the tolerance interval.
///
///
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_CPU_RATE_CONTROL, this member specifies the extent to which a
/// job can exceed its CPU rate control limits during the interval specified by the CpuRateControlToleranceInterval
/// member. Otherwise, this member is ignored.
///
/// This member can be one of the following values. If no value is specified, ToleranceHigh is used.
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceLow1
/// The job can exceed its CPU rate control limits for 20% of the tolerance interval.
///
/// -
/// ToleranceMedium2
/// The job can exceed its CPU rate control limits for 40% of the tolerance interval.
///
/// -
/// ToleranceHigh3
/// The job can exceed its CPU rate control limits for 60% of the tolerance interval.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE RateControlTolerance;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_RATE_CONTROL, this member specifies the interval during which a
/// job's CPU usage is monitored to determine whether the job has exceeded its CPU rate control limits. Otherwise, this member is ignored.
///
/// This member can be one of the following values. If no value is specified, ToleranceIntervalShort is used.
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceIntervalShort1
/// The tolerance interval is 10 seconds.
///
/// -
/// ToleranceIntervalMedium2
/// The tolerance interval is one minute.
///
/// -
/// ToleranceIntervalLong3
/// The tolerance interval is 10 minutes.
///
///
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_CPU_LIMIT_RATE_CONTROL, this member specifies the interval during
/// which a job's CPU usage is monitored to determine whether the job has exceeded its CPU rate control limits. Otherwise, this
/// member is ignored.
///
/// This member can be one of the following values. If no value is specified, ToleranceIntervalShort is used.
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceIntervalShort1
/// The tolerance interval is 10 seconds.
///
/// -
/// ToleranceIntervalMedium2
/// The tolerance interval is one minute.
///
/// -
/// ToleranceIntervalLong3
/// The tolerance interval is 10 minutes.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL RateControlToleranceInterval;
///
///
/// The limit flags that are in effect. This member is a bitfield that determines whether other structure members are used. Any
/// combination of the following values can be specified.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_LIMIT_JOB_MEMORY_HIGH0x00000200
///
/// Establishes the notification threshold for the job-wide sum of private committed memory for all processes associated with the
/// job. The JobHighMemoryLimit member contains additional information.
///
///
/// -
/// JOB_OBJECT_LIMIT_JOB_MEMORY_LOW0x00008000
///
/// Establishes the notification minimum for the job-wide sum of private committed memory for all processes associated with the
/// job. If this value is set, a notification is sent when the amount of private committed memory falls below this threshold. The
/// JobLowMemoryLimit member contains additional information.
///
///
/// -
/// JOB_OBJECT_LIMIT_JOB_READ_BYTES0x00010000
///
/// Establishes the I/O read bytes limit to the job-wide sum of I/O bytes read by all processes associated with the job. The
/// IoReadBytesLimit member contains more information.
///
///
/// -
/// JOB_OBJECT_LIMIT_JOB_WRITE_BYTES0x00020000
///
/// Establishes the I/O write bytes limit to the job-wide sum of I/O bytes written by all processes associated with the job. The
/// IoWriteBytesLimit member contains more information.
///
///
/// -
/// JOB_OBJECT_LIMIT_JOB_TIME0x00000004
///
/// Establishes the limit for user-mode execution time for the job. The PerJobUserTimeLimit member contains additional information.
///
///
/// -
/// JOB_OBJECT_LIMIT_CPU_RATE_CONTROL0x00040000
///
/// Establishes the notification threshold for the CPU rate control limits established for the job. The CpuRateControlTolerance
/// and CpuRateControlToleranceInterval members contain additional information.CPU rate control limits are established by calling
/// SetInformationJobObject with the JobObjectCpuRateInformationClass information class.
///
///
/// -
/// JOB_OBJECT_LIMIT_RATE_CONTROL0x00040000
///
/// Establishes the notification threshold for the CPU rate control limits established for the job. The RateControlTolerance and
/// RateControlToleranceInterval members contain additional information.CPU rate control limits are established by calling
/// SetInformationJobObject with the JobObjectCpuRateInformationClass information class.
///
///
/// -
/// JOB_OBJECT_LIMIT_IO_RATE_CONTROL0x00080000
///
/// Establishes the notification threshold for the I/O rate control limits established for the job. The IoRateControlTolerance
/// and IoRateControlToleranceInterval members contain additional information.I/O rate control limits are established by calling SetIoRateControlInformationJobObject.
///
///
/// -
/// JOB_OBJECT_LIMIT_NET_RATE_CONTROL0x00100000
///
/// Establishes the notification threshold for the network rate control limits established for the job. The
/// NetRateControlTolerance and NetRateControlToleranceInterval members contain additional information.Network rate control
/// limits are established by calling SetInformationJobObject with the JobObjectNetRateInformationClass information class.
///
///
///
///
///
public JOBOBJECT_LIMIT_FLAGS LimitFlags;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_IO_RATE_CONTROL, this member specifies the extent to which a
/// job can exceed its I/O rate control limits during the interval specified by the IoRateControlToleranceInterval member.
/// Otherwise, this member is ignored.
///
/// This member can be one of the following values. If no value is specified, ToleranceHigh is used.
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceLow1
/// The job can exceed its I/O rate control limits for 20% of the tolerance interval.
///
/// -
/// ToleranceMedium2
/// The job can exceed its I/O rate control limits for 40% of the tolerance interval.
///
/// -
/// ToleranceHigh3
/// The job can exceed its I/O rate control limits for 60% of the tolerance interval.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE IoRateControlTolerance;
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_JOB_MEMORY_LOW, this member is the notification limit minimum
/// for the total virtual memory that can be committed by all processes in the job, in bytes. Otherwise, this member is ignored.
///
public ulong JobLowMemoryLimit;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_IO_LIMIT_RATE_CONTROL, this member specifies the interval during
/// which a job's I/O usage is monitored to determine whether the job has exceeded its I/O rate control limits. Otherwise, this
/// member is ignored.
///
/// This member can be one of the following values. If no value is specified, ToleranceIntervalShort is used.
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceIntervalShort1
/// The tolerance interval is 10 seconds.
///
/// -
/// ToleranceIntervalMedium2
/// The tolerance interval is one minute.
///
/// -
/// ToleranceIntervalLong3
/// The tolerance interval is 10 minutes.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL IoRateControlToleranceInterval;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_LIMIT_IO_RATE_CONTROL, this member specifies the extent to which a
/// job can exceed its network rate control limits during the interval specified by the NetRateControlToleranceInterval
/// member. Otherwise, this member is ignored.
///
/// This member can be one of the following values. If no value is specified, ToleranceHigh is used.
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceLow1
/// The job can exceed its network rate control limits for 20% of the tolerance interval.
///
/// -
/// ToleranceMedium2
/// The job can exceed its network rate control limits for 40% of the tolerance interval.
///
/// -
/// ToleranceHigh3
/// The job can exceed its network rate control limits for 60% of the tolerance interval.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE NetRateControlTolerance;
///
///
/// If the LimitFlags parameter specifies JOB_OBJECT_NET_LIMIT_RATE_CONTROL, this member specifies the interval during
/// which a job's network usage is monitored to determine whether the job has exceeded its network rate control limits.
/// Otherwise, this member is ignored.
///
/// This member can be one of the following values. If no value is specified, ToleranceIntervalShort is used.
///
///
///
/// Value
/// Meaning
///
/// -
/// ToleranceIntervalShort1
/// The tolerance interval is 10 seconds.
///
/// -
/// ToleranceIntervalMedium2
/// The tolerance interval is one minute.
///
/// -
/// ToleranceIntervalLong3
/// The tolerance interval is 10 minutes.
///
///
///
///
public JOBOBJECT_RATE_CONTROL_TOLERANCE_INTERVAL NetRateControlToleranceInterval;
}
///
///
/// [JOBOBJECT_SECURITY_LIMIT_INFORMATION is available for use in the operating systems specified in the Requirements section.
/// Support for this structure was removed starting with Windows Vista. For information, see Remarks.]
///
/// Contains the security limitations for a job object.
///
// typedef struct _JOBOBJECT_SECURITY_LIMIT_INFORMATION { DWORD SecurityLimitFlags; HANDLE JobToken; PTOKEN_GROUPS SidsToDisable;
// PTOKEN_PRIVILEGES PrivilegesToDelete; PTOKEN_GROUPS RestrictedSids;} JOBOBJECT_SECURITY_LIMIT_INFORMATION,
// *PJOBOBJECT_SECURITY_LIMIT_INFORMATION; https://msdn.microsoft.com/en-us/library/windows/desktop/ms684159(v=vs.85).aspx
[PInvokeData("WinNT.h", MSDNShortId = "ms684159")]
[StructLayout(LayoutKind.Sequential)]
public struct JOBOBJECT_SECURITY_LIMIT_INFORMATION
{
///
/// The security limitations for the job. This member can be one or more of the following values.
///
///
///
/// Value
/// Meaning
///
/// -
/// JOB_OBJECT_SECURITY_FILTER_TOKENS0x00000008
///
/// Applies a filter to the token when a process impersonates a client. Requires at least one of the following members to be set:
/// SidsToDisable, PrivilegesToDelete, or RestrictedSids.
///
///
/// -
/// JOB_OBJECT_SECURITY_NO_ADMIN0x00000001
/// Prevents any process in the job from using a token that specifies the local administrators group.
///
/// -
/// JOB_OBJECT_SECURITY_ONLY_TOKEN0x00000004
/// Forces processes in the job to run under a specific token. Requires a token handle in the JobToken member.
///
/// -
/// JOB_OBJECT_SECURITY_RESTRICTED_TOKEN0x00000002
/// Prevents any process in the job from using a token that was not created with the CreateRestrictedToken function.
///
///
///
///
public JOBOBJECT_SECURITY_FLAGS SecurityLimitFlags;
///
/// A handle to the primary token that represents a user. The handle must have TOKEN_ASSIGN_PRIMARY access.
///
/// If the token was created with CreateRestrictedToken, all processes in the job are limited to that token or a further
/// restricted token. Otherwise, the caller must have the SE_ASSIGNPRIMARYTOKEN_NAME privilege.
///
///
public HTOKEN JobToken;
///
///
/// A pointer to a TOKEN_GROUPS structure that specifies the SIDs to disable for access checking, if
/// SecurityLimitFlags is JOB_OBJECT_SECURITY_FILTER_TOKENS.
///
/// This member can be NULL if you do not want to disable any SIDs.
///
public IntPtr SidsToDisable;
///
///
/// A pointer to a TOKEN_PRIVILEGES structure that specifies the privileges to delete from the token, if
/// SecurityLimitFlags is JOB_OBJECT_SECURITY_FILTER_TOKENS.
///
/// This member can be NULL if you do not want to delete any privileges.
///
public IntPtr PrivilegesToDelete;
///
///
/// A pointer to a TOKEN_GROUPS structure that specifies the deny-only SIDs that will be added to the access token, if
/// SecurityLimitFlags is JOB_OBJECT_SECURITY_FILTER_TOKENS.
///
/// This member can be NULL if you do not want to specify any deny-only SIDs.
///
public IntPtr RestrictedSids;
}
/// Provides a to a job object that releases a created HJOB instance at disposal using CloseHandle.
public class SafeHJOB : SafeSyncHandle
{
/// Initializes a new instance of the class and assigns an existing handle.
/// An object that represents the pre-existing handle to use.
///
/// to reliably release the handle during the finalization phase; otherwise, (not recommended).
///
public SafeHJOB(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
private SafeHJOB() : base()
{
}
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator HJOB(SafeHJOB h) => h.handle;
}
}
}