Ejemplo n.º 1
0
        public static ExtendedLimitInformation GetExtendedLimitInformation(int maximumTime, int maximumMemory)
        {
            var info = new BasicLimitInformation
            {
                LimitFlags =
                    (int)(LimitFlags.JOB_OBJECT_LIMIT_JOB_MEMORY
                          //// The following two flags are causing the process to have unexpected behavior
                          //// | LimitFlags.JOB_OBJECT_LIMIT_JOB_TIME
                          //// | LimitFlags.JOB_OBJECT_LIMIT_PROCESS_TIME
                          | LimitFlags.JOB_OBJECT_LIMIT_ACTIVE_PROCESS
                          | LimitFlags.JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION
                          | LimitFlags.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE),
                PerJobUserTimeLimit     = maximumTime, // TODO: Remove or rework
                PerProcessUserTimeLimit = maximumTime,
                ActiveProcessLimit      = 1,
            };

            var extendedInfo = new ExtendedLimitInformation
            {
                BasicLimitInformation = info,
                JobMemoryLimit        = (UIntPtr)maximumMemory,
                IoInfo =
                {
                    ReadTransferCount   = 0,
                    ReadOperationCount  = 0,
                    WriteOperationCount = 0,
                    WriteTransferCount  = 0
                }
            };

            return(extendedInfo);
        }
        public static ExtendedLimitInformation GetExtendedLimitInformation(int maximumTime, int maximumMemory)
        {
            var info = new BasicLimitInformation
            {
                LimitFlags = (int)
                    (LimitFlags.JOB_OBJECT_LIMIT_JOB_MEMORY
                     //// The following two flags are causing the process to have unexpected behavior
                     //// | LimitFlags.JOB_OBJECT_LIMIT_JOB_TIME
                     //// | LimitFlags.JOB_OBJECT_LIMIT_PROCESS_TIME
                     | LimitFlags.JOB_OBJECT_LIMIT_ACTIVE_PROCESS
                     | LimitFlags.JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION
                     | LimitFlags.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE),
                PerJobUserTimeLimit = maximumTime, // TODO: Remove or rework
                PerProcessUserTimeLimit = maximumTime,
                ActiveProcessLimit = 1,
            };

            var extendedInfo = new ExtendedLimitInformation
            {
                BasicLimitInformation = info,
                JobMemoryLimit = (UIntPtr)maximumMemory,
                IoInfo =
                {
                    ReadTransferCount = 0,
                    ReadOperationCount = 0,
                    WriteOperationCount = 0,
                    WriteTransferCount = 0
                }
            };

            return extendedInfo;
        }
Ejemplo n.º 3
0
 public ExtendedLimitInformation GetExtendedLimitInformation()
 {
     var extendedLimitInformation = new ExtendedLimitInformation();
     var length = Marshal.SizeOf(typeof(ExtendedLimitInformation));
     var extendedLimitInformationInfoPointer = Marshal.AllocHGlobal(length);
     Marshal.StructureToPtr(extendedLimitInformation, extendedLimitInformationInfoPointer, false);
     QueryInformationJobObject(this.handle, InfoClass.ExtendedLimitInformation, out extendedLimitInformationInfoPointer, (uint)length, IntPtr.Zero);
     return extendedLimitInformation;
 }
Ejemplo n.º 4
0
        public ExtendedLimitInformation GetExtendedLimitInformation()
        {
            var extendedLimitInformation = new ExtendedLimitInformation();
            var length = Marshal.SizeOf(typeof(ExtendedLimitInformation));
            var extendedLimitInformationInfoPointer = Marshal.AllocHGlobal(length);

            Marshal.StructureToPtr(extendedLimitInformation, extendedLimitInformationInfoPointer, false);
            NativeMethods.QueryInformationJobObject(this.handle, InfoClass.ExtendedLimitInformation, out extendedLimitInformationInfoPointer, (uint)length, IntPtr.Zero);
            return(extendedLimitInformation);
        }
Ejemplo n.º 5
0
        public void SetExtendedLimitInformation(ExtendedLimitInformation extendedInfo)
        {
            var length = Marshal.SizeOf(typeof(ExtendedLimitInformation));
            var extendedInfoPointer = Marshal.AllocHGlobal(length);

            Marshal.StructureToPtr(extendedInfo, extendedInfoPointer, false);
            if (!NativeMethods.SetInformationJobObject(this.handle, InfoClass.ExtendedLimitInformation, extendedInfoPointer, (uint)length))
            {
                throw new Win32Exception();
            }
        }
Ejemplo n.º 6
0
 public void SetExtendedLimitInformation(ExtendedLimitInformation extendedInfo)
 {
     var length = Marshal.SizeOf(typeof(ExtendedLimitInformation));
     var extendedInfoPointer = Marshal.AllocHGlobal(length);
     Marshal.StructureToPtr(extendedInfo, extendedInfoPointer, false);
     if (!SetInformationJobObject(this.handle, InfoClass.ExtendedLimitInformation, extendedInfoPointer, (uint)length))
     {
         throw new Win32Exception();
     }
 }