Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
限制从net start命令运行的Windows服务使用的CPU内核数_Windows_Command Line_Windows Services - Fatal编程技术网

限制从net start命令运行的Windows服务使用的CPU内核数

限制从net start命令运行的Windows服务使用的CPU内核数,windows,command-line,windows-services,Windows,Command Line,Windows Services,我正在Windows 10上运行PostgreSQL 12的基准测试。我想限制PostgreSQL服务使用的CPU内核数量,以测试CPU性能如何影响TPU 现在,我使用以下命令启动PostgreSQL服务: net start postgresql-x64-12 我知道如何限制普通Windows应用程序的CPU内核数量,如: start /affinity 1 "" "C:\Windows\System32\calc.exe" cmd.exe /c "start /affinity 1F

我正在Windows 10上运行PostgreSQL 12的基准测试。我想限制PostgreSQL服务使用的CPU内核数量,以测试CPU性能如何影响TPU

现在,我使用以下命令启动PostgreSQL服务:

 net start postgresql-x64-12
我知道如何限制普通Windows应用程序的CPU内核数量,如:

 start /affinity 1 "" "C:\Windows\System32\calc.exe"
cmd.exe /c "start /affinity 1F /B c:\path\to\PostgreSQL\12\bin\pg_ctl.exe start -w -s -D C:\path\to\PostgreSQL\12\data"

如何限制从net start命令运行的Windows服务使用的CPU内核数?在
net start
命令中是否有一个
/affinity
选项等效?

我找到了一个解决方案。首先,不能将CPU关联设置为Windows系统进程或服务(请参阅(日语))

在我的情况下,我可以通过cmd.exe中的
/affinity
选项从
pg_ctl
命令运行PostgreSQL进程,如下所示:

 start /affinity 1 "" "C:\Windows\System32\calc.exe"
cmd.exe /c "start /affinity 1F /B c:\path\to\PostgreSQL\12\bin\pg_ctl.exe start -w -s -D C:\path\to\PostgreSQL\12\data"
请注意,您不能像这样使用
Start Process
cmdlet和
ProcessorAffinity
属性:

$app = Start-Process 'c:\path\to\PostgreSQL\12\bin\pg_ctl.exe' 'start -D C:\path\to\PostgreSQL\12\data' -PassThru -NoNewWindow
$app.ProcessorAffinity = 0x3
这会导致
SetValueInvocationException
,因为
pg_ctl.exe
在启动PostgreSQL实例后会立即退出