Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

taskset equivalent in windows

In Linux, there's the taskset utility which allows you to set CPU affinity for a certain process.

Is there an equivalent in the Windows environment?
I want to set a maximum CPU threshold for my product, is there any existing mechanism in Windows that offers this capabilities?

If its any help, my product is developed in .Net

Thanks

like image 452
sternr Avatar asked May 31 '12 08:05

sternr


1 Answers

Yes, there is:

Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
  [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
  [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
  [command/program] [parameters]

and the option /AFFINITY <hex affinity mask> in particular.

AFFINITY    Specifies the processor affinity mask as a hexadecimal number.
            The process is restricted to running on these processors.

            The affinity mask is interpreted differently when /AFFINITY and
            /NODE are combined.  Specify the affinity mask as if the NUMA
            node's processor mask is right shifted to begin at bit zero.
            The process is restricted to running on those processors in
            common between the specified affinity mask and the NUMA node.
            If no processors are in common, the process is restricted to
            running on the specified NUMA node.

If you'd like to bind to CPU 0 only, then specify affinity mask of 0x1. To bind to CPU 1 the mask should be 0x2. To bind to CPU 0 and CPU 1 the mask should be 0x3, and so on.

You can also set the CPU affinity in code by assigning the same hexadecimal mask value to the ProcessorAffinity property of the instance of the current process obtainable by calling System.Diagnostics.Process.GetCurrentProcess():

using System.Diagnostics;

Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)0x3;
like image 134
Hristo Iliev Avatar answered Sep 22 '22 14:09

Hristo Iliev