How can I set the maximum number of threads for a specific process?

709 views Asked by At

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.

2

There are 2 answers

0
Gabi Turliu On BEST ANSWER

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.

0
Remy Lebeau On

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.