本文介绍了在批处理文件中启动多个进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是根据给定计算机上的cpu内核数在批处理文件中启动多个进程.我想出了下面的脚本,该脚本似乎运行良好,但不确定这是否是最理想的方法.

My goal is to start multiple processes inside a batch file based on number of cpu cores on a given machine. I came up with the script below which seems to be working fine but not sure if this is the most optimal way of doing it.

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set arg1=%1

FOR /F "tokens=* USEBACKQ" %%F IN (`wmic cpu get NumberOfCores`) DO (
  SET str=%%F
 )
set str=%str:NumberOfCores =%
FOR /L %%n IN (1,1, %str% ) DO ( start %arg1% )

推荐答案

有一个误解,环境变量NUMBER_OF_PROCESSORS表示处理器的逻辑数量,它不是cpu套接字的数量,但最终是内核数量的两倍使用HT/SMT.

There is a misunderstanding, the environment variable NUMBER_OF_PROCESSORS represents the logical number of processor which isn't the number of cpu sockets but the number of cores eventually doubled with HT/SMT.

请参阅此wmic命令的输出

See the ouput of this wmic command

> wmic cpu get NumberOfCores,NumberOfEnabledCore,NumberOfLogicalProcessors /value

NumberOfCores=4
NumberOfEnabledCore=4
NumberOfLogicalProcessors=8

NUMBER_OF_PROCESSORS一样频繁地使用启动不能保证启动的程序分布在逻辑处理器上.读取start /? =>节点亲和力

Using start as often as NUMBER_OF_PROCESSORS doesn't guarantee the started program is distributed on the logical processors. Read start /? => Node,Affinity

@Echo off
For /f %%A in ('wmic cpu get NumberOfCores /value^|find "="') Do Set /A %%A
Set Num

示例输出:

NumberOfCores=4
NUMBER_OF_PROCESSORS=8

这篇关于在批处理文件中启动多个进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:22