2011-10-23 9 views
3

アフィニティを設定する方法はありますか?すべて Windows 7でプロセスを実行していますか?WIndows 7で実行中のすべてのプロセスのアフィニティをプログラムで設定するにはどうすればよいですか?

いくつかのハイパースレッディングベンチマークを実行したいと思います。これらのベンチマークが特定のコアで単独で実行されていることを確認したいと思います。私はラッパーでそれらを実行している、と私は、この(擬似コードで)のような何かをしたい:

foreach process in <list of all processes> 
    set affinity to all cores but core x 

set affinity of the current process to core x 

run benchmark 0 on core x thread 0 
run benchmark 1 on core x thread 1 

さて、私は現在のプロセスの親和性とその子を設定する方法を知っていると思いますが、どのようにすることができます:

  1. すべてのプロセスにわたって繰り返しますか?
  2. 他のプロセスの親和性を設定しますか?
+1

あなたがトラブル特定のプロセスを開くを持っている場合は、 'SeDebugPrivilege'(あなたのプログラムが管理者として実行する必要があり)を取得する必要があります。 – CodesInChaos

答えて

3

This project on CodeProjectは、すべてのプロセスを列挙して優先度を変更する方法を示しています。 1行の変更はそれを調整してすべてのプロセスを列挙し、それらの親和性を変更します。 SetProcessPriorityからSetProcessAffinityMaskに変更してください。次の構文で起動時に実行する

+0

システムプロセスとサービスのアフィニティマスクを設定できるようにするには、サービスとして実行する必要があると思われます。そして、それでもカーネルスレッドの親和性を設定することはほとんどできません。 – Gabe

+2

一度に不可能なもの... –

+0

何かをサービスとして実行することについてはどこで知ることができますか? –

0

Iセットアップスケジュールされたタスクトリガー:Windows 7の上で正常にテスト

start /affinity 1 java.exe 

3

ここではそれをしないパワーシェルスクリプトです。必要に応じて、追加のbatファイルで実行することもできます。 次に、タスクマネージャーで、ベンチマークの親和性を設定します。

run_set_affinity.bat:

powershell -executionpolicy bypass -file set_affinity.ps1 

set_affinity.ps1:

# elevate privileges if we are not running as Administrator, so we can set affinity of Windows owned processes 
# source: http://superuser.com/questions/108207/how-to-run-a-powershell-script-as-administrator 

param([switch]$Elevated) 

function Test-Admin { 
    $currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) 
    $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) 
} 

if ((Test-Admin) -eq $false) { 
    if ($elevated) { 
     'tried to elevate to full privileges, did not work, aborting' 
    } else { 
     'running my self again with full privileges' 
     Start-Process powershell.exe -Verb RunAs -ArgumentList ('-executionpolicy bypass -noprofile -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition)) 
    } 
    exit 
} 
'running with full privileges' 





# set affinity of all processes to CPU 3 and CPU 4 
# it prints processes that it was unable to set affinity of  
# source: https://digitaljive.wordpress.com/2011/11/18/set-processor-affinity-with-powershell/ 

# 1 (CPU 1) 
# 2 (CPU 2) 
# 4 (CPU 3) 
# 8 (CPU 4) 
# 16 (CPU 5) 
# 32 (CPU 6) 
# 64 (CPU 7) 
# 128 (CPU 8) 

$affinity = 4 + 8 
'setting all processes to affinity: '+$affinity 
'processes unable to set affinity of: ' 

$allProcesses = Get-Process * 
foreach ($process in $allProcesses) { 
    try { 
     $process.ProcessorAffinity = $affinity 
    } 
    catch { 
     $process 
    } 
} 
+0

これは本当にうまくいきます! –

関連する問題