0

I am using CreateProcessAsUser Windows API method to create process. I am creating the process with a security token and add it to a job object.

Can I limit the maximum number of threads for the process I am staring using either security token or job object or any other method?

I am using C# but the language doesn't matter if the solution involves calling direct Windows API calls.

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
  • 1
    I think you need to consider what would happen when the process attempted to create a new thread and failed. (In particular, what if the Windows API attempts to create a new thread and fails? The API call will fail for no readily apparent reason.) You can, however, specify which CPU cores the process will be allowed to use, and in Windows 8 you can specify a maximum CPU percentage. – Harry Johnston Sep 11 '13 at 22:36
  • @HarryJohnston, thanks for your comment! I will consider CPU usage limitations. – Nikolay Kostov Sep 12 '13 at 08:38

2 Answers2

3

You can't control the number of threads your process will have, except if you write the code for that specific process and manually take care of this problem. Windows doesn't have a limit for the threads per process, it's just a matter of address space usage, so not only you can't set that limit for a specific process, but you can't set it for the whole system.

Gabi Turliu
  • 226
  • 1
  • 5
1

The number of threads a process can create is limited only by available resources. There is no way to set a process's thread limit, especially externally.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770