Share via


SetProcessInformation 関数 (processthreadsapi.h)

指定したプロセスの情報を設定します。

構文

BOOL SetProcessInformation(
  [in] HANDLE                    hProcess,
  [in] PROCESS_INFORMATION_CLASS ProcessInformationClass,
       LPVOID                    ProcessInformation,
  [in] DWORD                     ProcessInformationSize
);

パラメーター

[in] hProcess

プロセスのハンドル。 このハンドルには、 PROCESS_SET_INFORMATION アクセス権が必要です。 詳細については、「 セキュリティとアクセス権の処理」を参照してください。

[in] ProcessInformationClass

設定する情報の種類を指定する PROCESS_INFORMATION_CLASS 列挙体のメンバー。

ProcessInformation

ProcessInformationClass パラメーターで指定された情報の種類を含むオブジェクトへのポインター。

ProcessInformationClass パラメーターが ProcessMemoryPriority の場合、このパラメーターは構造体MEMORY_PRIORITY_INFORMATION MEMORY_PRIORITY_INFORMATION構造体を指す必要があります。

ProcessInformationClass パラメーターが ProcessPowerThrottling の場合、このパラメーターはPROCESS_POWER_THROTTLING_STATE構造体を指す必要があります。

ProcessInformationClass パラメーターが ProcessLeapSecondInfo の場合、このパラメーターはPROCESS_LEAP_SECOND_INFO構造体を指す必要があります。

ProcessInformationClass パラメーターが ProcessOverrideSubsequentPrefetchParameter の場合、このパラメーターはOVERRIDE_PREFETCH_PARAMETER構造体を指す必要があります。

[in] ProcessInformationSize

ProcessInformation パラメーターで指定された構造体のサイズ (バイト単位)。

ProcessInformationClass パラメーターが ProcessMemoryPriority の場合、このパラメーターは であるsizeof(MEMORY_PRIORITY_INFORMATION)必要があります。

ProcessInformationClass パラメーターが ProcessPowerThrottling の場合、このパラメーターは であるsizeof(PROCESS_POWER_THROTTLING_STATE)必要があります。

ProcessInformationClass パラメーターが ProcessLeapSecondInfo の場合、このパラメーターは であるsizeof(PROCESS_LEAP_SECOND_INFO)必要があります。

戻り値

関数が成功すると、戻り値は 0 以外になります。

関数が失敗した場合は、0 を返します。 詳細なエラー情報を得るには、GetLastError を呼び出します。

解説

システム のパフォーマンスを向上させるには、アプリケーションで ProcessMemoryPriority共に SetProcessInformation 関数を使用して、バックグラウンド操作を実行するスレッドの既定のメモリ優先度を下げるか、ファイルやデータにアクセスする予定のないファイルとデータにすぐにアクセスする必要があります。 たとえば、ファイル インデックス作成アプリケーションでは、インデックス作成タスクを実行するプロセスの既定の優先順位を低く設定できます。

メモリ優先度 は、ページがトリミングされるまでにプロセスの ワーキング セット 内に残っている時間を判断するのに役立ちます。 プロセスのメモリ優先度は、そのプロセスのスレッドによって設定されたプロセスに追加される物理ページの既定の優先度を決定します。 メモリ マネージャーは、ワーキング セットをトリミングすると、優先度の低いページを優先度の高いページの前にトリミングします。 これにより、優先度の高いページがワーキング セットからトリミングされる可能性が低くなり、再びアクセスされたときにページ フォールトがトリガーされるため、システム全体のパフォーマンスが向上します。

ProcessPowerThrottling を使用すると、最適なパフォーマンスが必要ない場合にパフォーマンスと電力効率のバランスを取るために使用できる、プロセスの調整ポリシーが有効になります。

プロセスが を有効にすることを PROCESS_POWER_THROTTLING_EXECUTION_SPEED選択すると、プロセスは EcoQoS として分類されます。 システムは、CPU 周波数の削減や、より電力効率の高いコアの使用などの戦略を通じて、電力効率の向上を試みます。 EcoQoS は、作業がフォアグラウンドのユーザー エクスペリエンスに貢献していない場合に使用する必要があります。これにより、バッテリ寿命が長くなり、熱とファンのノイズが軽減されます。 EcoQoS は、パフォーマンスクリティカルまたはフォアグラウンドのユーザー エクスペリエンスには使用しないでください。 (Windows 11より前は、EcoQoS レベルは存在せず、プロセスは LowQoS とラベル付けされていました)。 アプリケーションで を明示的に有効 PROCESS_POWER_THROTTLING_EXECUTION_SPEEDにしない場合、システムは独自のヒューリスティックを使用して、サービス品質レベルを自動的に推論します。 詳細については、「サービスの品質」を参照してください。

プロセスが を有効 PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTIONにすることを選択すると、プロセスによって行われた現在のタイマー解決要求はすべて無視されます。 プロセスに属するタイマーは、より高いタイマー解像度で期限切れになることが保証されなくなり、電力効率が向上する可能性があります。 を明示的に無効 PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTIONにした後、システムはプロセスによって以前のタイマー解決要求を記憶し、優先します。 既定では、Windows 11ウィンドウ所有プロセスがエンド ユーザーに対して完全に隠された、最小化された、またはその他の方法で表示されなくなり、聞こえない場合、Windows はタイマー解決要求を自動的に無視する可能性があるため、既定のシステム解像度よりも高い解像度を保証しません。

次の例では、ProcessMemoryPriority を使用して SetProcessInformation を呼び出して、呼び出し元プロセスの既定値としてメモリ優先度を低く設定する方法を示します。

    DWORD ErrorCode;
    BOOL Success;
    MEMORY_PRIORITY_INFORMATION MemPrio;

    //
    // Set low memory priority on the current process.
    //

    ZeroMemory(&MemPrio, sizeof(MemPrio));
    MemPrio.MemoryPriority = MEMORY_PRIORITY_LOW;

    Success = SetProcessInformation(GetCurrentProcess(),
                                   ProcessMemoryPriority,
                                   &MemPrio,
                                   sizeof(MemPrio));

    if (!Success) {
        ErrorCode = GetLastError();
        fprintf(stderr, "Set process memory priority failed: %d\n", ErrorCode);
        goto cleanup;
    }

次の例は、ProcessPowerThrottling を使用して SetProcessInformation を呼び出して、プロセスのサービス品質を制御する方法を示しています。

PROCESS_POWER_THROTTLING_STATE PowerThrottling;
RtlZeroMemory(&PowerThrottling, sizeof(PowerThrottling));
PowerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;

//
// EcoQoS
// Turn EXECUTION_SPEED throttling on. 
// ControlMask selects the mechanism and StateMask declares which mechanism should be on or off.
//

PowerThrottling.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
PowerThrottling.StateMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;

SetProcessInformation(GetCurrentProcess(), 
                      ProcessPowerThrottling, 
                      &PowerThrottling,
                      sizeof(PowerThrottling));

//
// HighQoS
// Turn EXECUTION_SPEED throttling off. 
// ControlMask selects the mechanism and StateMask is set to zero as mechanisms should be turned off.
//

PowerThrottling.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
PowerThrottling.StateMask = 0;

SetProcessInformation(GetCurrentProcess(), 
                      ProcessPowerThrottling, 
                      &PowerThrottling,
                      sizeof(PowerThrottling));

次の例は、ProcessPowerThrottling を使用して SetProcessInformation を呼び出して、プロセスのタイマー解決を制御する方法を示しています。

PROCESS_POWER_THROTTLING_STATE PowerThrottling;
RtlZeroMemory(&PowerThrottling, sizeof(PowerThrottling));
PowerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;

//
// Ignore Timer Resolution Requests.
// Turn IGNORE_TIMER_RESOLUTION throttling on. 
// ControlMask selects the mechanism and StateMask declares which mechanism should be on or off.
//

PowerThrottling.ControlMask = PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION;
PowerThrottling.StateMask = PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION;

SetProcessInformation(GetCurrentProcess(), 
                      ProcessPowerThrottling, 
                      &PowerThrottling,
                      sizeof(PowerThrottling));

//
// Always honor Timer Resolution Requests.
// Turn IGNORE_TIMER_RESOLUTION throttling off. 
// ControlMask selects the mechanism and StateMask is set to zero as mechanisms should be turned off.
//

PowerThrottling.ControlMask = PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION;
PowerThrottling.StateMask = 0;

SetProcessInformation(GetCurrentProcess(), 
                      ProcessPowerThrottling, 
                      &PowerThrottling,
                      sizeof(PowerThrottling));

次の例は、ProcessPowerThrottling を使用して SetProcessInformation を呼び出して、既定のシステムマネージド動作にリセットする方法を示しています。

PROCESS_POWER_THROTTLING_STATE PowerThrottling;
RtlZeroMemory(&PowerThrottling, sizeof(PowerThrottling));
PowerThrottling.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;

//
// Let system manage all power throttling. ControlMask is set to 0 as we don't want 
// to control any mechanisms.
//

PowerThrottling.ControlMask = 0;
PowerThrottling.StateMask = 0;

SetProcessInformation(GetCurrentProcess(), 
                      ProcessPowerThrottling, 
                      &PowerThrottling,
                      sizeof(PowerThrottling));
 

要件

要件
サポートされている最小のクライアント Windows 8 [デスクトップ アプリ |UWP アプリ]
サポートされている最小のサーバー Windows Server 2012 [デスクトップ アプリ |UWP アプリ]
対象プラットフォーム Windows
ヘッダー processthreadsapi.h (Windows.h を含む)
Library Kernel32.lib
[DLL] Kernel32.dll

関連項目

GetProcessInformation 関数SetThreadInformation 関数MEMORY_PRIORITY_INFORMATION構造体SetProcessInformation 関数PROCESS_INFORMATION_CLASS列挙OVERRIDE_PREFETCH_PARAMETER構造体