Limiting user processor time and peek virtual memory with Job Objects

mario

I'm writing an application runner on Windows which can limit processor user time and virtual memory for the application it will run. Idea is to have following:

runner.exe mem_limit_in_MB time_limit_in_sec command.exe command_arguments ...

My investigation lead me to Windows Job Objects API and since I'm trying to do all that from C#, I found JobObjectWrapper to help me.

The main part of the code if following:

using (JobObject jo = new JobObject())
{
    // Time
    jo.Limits.PerProcessUserTimeLimit = TimeSpan.FromMilliseconds(limitTime);
    jo.Events.OnEndOfProcessTime += new jobEventHandler<EndOfProcessTimeEventArgs>(Events_OnEndOfProcessTime);

    // Memory
    jo.Limits.ProcessMemoryLimit = new IntPtr(limitMemory);
    jo.Events.OnProcessMemoryLimit += new jobEventHandler<ProcessMemoryLimitEventArgs>(Events_OnProcessMemoryLimit);

    // Process
    ProcessStartInfo psi = new ProcessStartInfo(command, arguments);
    psi.UseShellExecute = false;
    psi.RedirectStandardOutput = true;

    jo.Limits.IsChildProcessBreakAway = false;
    Process p = jo.CreateProcessSecured(psi);

    p.WaitForExit();
}

Now, the problem is that it seams that Events_OnEndOfProcessTime is not called timely. If I set 0.5 sec limit for an app that takes several minutes, depending on the run application is once terminated after 0.5 sec and sometimes after 4 sec. Why is this happening? I cannot find any reference if Job Objects are checking limits periodically or in real-time.

My question is two-fold: - Does anyone know about already developed code that does what I need? - Does anyone know if Job Objects are executed periodically or in real time?

Thanks in advance...

Arno

PerProcessUserTimeLimit specifies the amount of user-mode time is granted to the process.

"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." (MSDN)

Consequently it depends on your application, particulary on how effient it is burning user-mode time. Ending a process with PerProcessUserTimeLimit = 0.5 after 0.5 sec. means that it has used ~100% cpu (user-mode) during that time.

... if Job Objects are executed periodically or in real time? Periodically, as stated above.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Is there a way of limiting the Kernel's memory manager to use only 75% of memory?

분류에서Dev

Is virtual memory real or is it just a method to manage the memory

분류에서Dev

Memory management of objects in java

분류에서Dev

Why is there no memory leak with non-virtual destructor

분류에서Dev

Is it possible to manually send programs to virtual memory in windows?

분류에서Dev

Confusion is memory allocation for pointers and virtual functions

분류에서Dev

How does virtual memory maintains its efficiency?

분류에서Dev

Alfresco trashcanCleaner job triggered not at preset time

분류에서Dev

Why is MATLAB job taking a long time running?

분류에서Dev

Boot time over 20 minutes on a virtual server

분류에서Dev

HashMap fails for user defined objects?

분류에서Dev

Problem in understanding Python memory allocation for list of objects

분류에서Dev

Why do JVM relocate objects in memory?

분류에서Dev

Excessive virtual memory/page file - Can I tone it down for space?

분류에서Dev

malloc in child thread cost too much virtual memory

분류에서Dev

Before Virtual destructor concept, all programs had memory leak?

분류에서Dev

Is a page contiguous in the virtual address space or physical memory or both?

분류에서Dev

How do I make Firefox in Lubuntu use less virtual memory?

분류에서Dev

Memory allocation to static variables (Compile time memory allocation)

분류에서Dev

Reflect User Preferences in Design Time

분류에서Dev

android check heap memory in run time

분류에서Dev

Rails: How to only allow User to apply to job only once?

분류에서Dev

No job jar file found. User classes may not be used

분류에서Dev

Run multiple cron jobs where one job takes a long time

분류에서Dev

How to watch live objects at run time

분류에서Dev

Compute the frequency of objects over time in Matlab

분류에서Dev

force cakephp 3 auth->user() to show virtual fields

분류에서Dev

How to Convert Time to Json Format with user given time?

분류에서Dev

show default time when user loads the page

Related 관련 기사

  1. 1

    Is there a way of limiting the Kernel's memory manager to use only 75% of memory?

  2. 2

    Is virtual memory real or is it just a method to manage the memory

  3. 3

    Memory management of objects in java

  4. 4

    Why is there no memory leak with non-virtual destructor

  5. 5

    Is it possible to manually send programs to virtual memory in windows?

  6. 6

    Confusion is memory allocation for pointers and virtual functions

  7. 7

    How does virtual memory maintains its efficiency?

  8. 8

    Alfresco trashcanCleaner job triggered not at preset time

  9. 9

    Why is MATLAB job taking a long time running?

  10. 10

    Boot time over 20 minutes on a virtual server

  11. 11

    HashMap fails for user defined objects?

  12. 12

    Problem in understanding Python memory allocation for list of objects

  13. 13

    Why do JVM relocate objects in memory?

  14. 14

    Excessive virtual memory/page file - Can I tone it down for space?

  15. 15

    malloc in child thread cost too much virtual memory

  16. 16

    Before Virtual destructor concept, all programs had memory leak?

  17. 17

    Is a page contiguous in the virtual address space or physical memory or both?

  18. 18

    How do I make Firefox in Lubuntu use less virtual memory?

  19. 19

    Memory allocation to static variables (Compile time memory allocation)

  20. 20

    Reflect User Preferences in Design Time

  21. 21

    android check heap memory in run time

  22. 22

    Rails: How to only allow User to apply to job only once?

  23. 23

    No job jar file found. User classes may not be used

  24. 24

    Run multiple cron jobs where one job takes a long time

  25. 25

    How to watch live objects at run time

  26. 26

    Compute the frequency of objects over time in Matlab

  27. 27

    force cakephp 3 auth->user() to show virtual fields

  28. 28

    How to Convert Time to Json Format with user given time?

  29. 29

    show default time when user loads the page

뜨겁다태그

보관