Función SetProcessInformation (processthreadsapi.h)

Establece información para el proceso especificado.

Sintaxis

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

Parámetros

[in] hProcess

Identificador del proceso. Este identificador debe tener el derecho de acceso PROCESS_SET_INFORMATION . Para obtener más información, consulte Derechos de acceso y seguridad de procesos.

[in] ProcessInformationClass

Miembro de la enumeración PROCESS_INFORMATION_CLASS que especifica el tipo de información que se va a establecer.

ProcessInformation

Puntero a un objeto que contiene el tipo de información especificada por el parámetro ProcessInformationClass .

Si el parámetro ProcessInformationClass es ProcessMemoryPriority, este parámetro debe apuntar a una estructura de MEMORY_PRIORITY_INFORMATIONMEMORY_PRIORITY_INFORMATION estructura.

Si el parámetro ProcessInformationClass es ProcessPowerThrottling, este parámetro debe apuntar a una estructura PROCESS_POWER_THROTTLING_STATE.

Si el parámetro ProcessInformationClass es ProcessLeapSecondInfo, este parámetro debe apuntar a una estructura PROCESS_LEAP_SECOND_INFO.

Si el parámetro ProcessInformationClass es ProcessOverrideSubsequentPrefetchParameter, este parámetro debe apuntar a una estructura OVERRIDE_PREFETCH_PARAMETER.

[in] ProcessInformationSize

Tamaño en bytes de la estructura especificada por el parámetro ProcessInformation .

Si el parámetro ProcessInformationClass es ProcessMemoryPriority, este parámetro debe ser sizeof(MEMORY_PRIORITY_INFORMATION).

Si el parámetro ProcessInformationClass es ProcessPowerThrottling, este parámetro debe ser sizeof(PROCESS_POWER_THROTTLING_STATE).

Si el parámetro ProcessInformationClass es ProcessLeapSecondInfo, este parámetro debe ser sizeof(PROCESS_LEAP_SECOND_INFO).

Valor devuelto

Si la función se realiza correctamente, el valor devuelto es distinto de cero.

Si la función no se realiza correctamente, el valor devuelto es cero. Para obtener información de error extendida, llame a GetLastError.

Comentarios

Para ayudar a mejorar el rendimiento del sistema, las aplicaciones deben usar la función SetProcessInformation con ProcessMemoryPriority para reducir la prioridad de memoria predeterminada de los subprocesos que realizan operaciones en segundo plano o acceden a archivos y datos a los que no se espera que se vuelva a acceder pronto. Por ejemplo, una aplicación de indexación de archivos podría establecer una prioridad predeterminada menor para el proceso que realiza la tarea de indexación.

La prioridad de memoria ayuda a determinar cuánto tiempo permanecen las páginas en el conjunto de trabajo de un proceso antes de que se recorten. La prioridad de memoria de un proceso determina la prioridad predeterminada de las páginas físicas que se agregan al conjunto de trabajo del proceso por los subprocesos de ese proceso. Cuando el administrador de memoria recorta el espacio de trabajo, recorta las páginas de prioridad inferior antes de las páginas de prioridad más alta. Esto mejora el rendimiento general del sistema porque es menos probable que las páginas de prioridad más alta se recorten del espacio de trabajo y, a continuación, desencadenen un error de página cuando se vuelva a acceder a ellas.

ProcessPowerThrottling permite la limitación de directivas en un proceso, que se puede usar para equilibrar el rendimiento y la eficiencia energética en los casos en los que no se requiere un rendimiento óptimo.

Cuando un proceso opta por habilitar PROCESS_POWER_THROTTLING_EXECUTION_SPEED, el proceso se clasificará como EcoQoS. El sistema intentará aumentar la eficiencia energética mediante estrategias como reducir la frecuencia de CPU o usar núcleos más eficientes. EcoQoS debe utilizarse cuando el trabajo no contribuye a la experiencia del usuario en primer plano, lo que proporciona una mayor duración de la batería y reduce el ruido de calor y ventilador. EcoQoS no debe usarse para experiencias de usuario críticas o en primer plano del rendimiento. (Antes de Windows 11, el nivel EcoQoS no existía y el proceso se etiquetaba como LowQoS). Si una aplicación no habilita PROCESS_POWER_THROTTLING_EXECUTION_SPEEDexplícitamente , el sistema usará su propia heurística para deducir automáticamente un nivel de calidad de servicio. Para obtener más información, consulte Calidad de servicio.

Cuando un proceso opta por habilitar PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION, se omitirán las solicitudes de resolución del temporizador actuales realizadas por el proceso. Ya no se garantiza que los temporizadores que pertenecen al proceso expiren con una mayor resolución del temporizador, lo que puede mejorar la eficiencia energética. Después de deshabilitar PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTIONexplícitamente , el sistema recuerda y respeta cualquier solicitud de resolución del temporizador anterior por el proceso. De forma predeterminada, en Windows 11 si un proceso propietario de ventanas se ocluye completamente, minimizado o no visible para el usuario final y, de lo contrario, Windows puede omitir automáticamente la solicitud de resolución del temporizador y, por tanto, no garantiza una resolución mayor que la resolución predeterminada del sistema.

Ejemplos

En el ejemplo siguiente se muestra cómo llamar a SetProcessInformation con ProcessMemoryPriority para establecer una prioridad de memoria baja como valor predeterminado para el proceso de llamada.

    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;
    }

En el ejemplo siguiente se muestra cómo llamar a SetProcessInformation con ProcessPowerThrottling para controlar la calidad de servicio de un proceso.

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));

En el ejemplo siguiente se muestra cómo llamar a SetProcessInformation con ProcessPowerThrottling para controlar la resolución del temporizador de un proceso.

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));

En el ejemplo siguiente se muestra cómo llamar a SetProcessInformation con ProcessPowerThrottling para restablecer el comportamiento administrado por el sistema predeterminado.

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));
 

Requisitos

Requisito Value
Cliente mínimo compatible Windows 8 [aplicaciones de escritorio | Aplicaciones para UWP]
Servidor mínimo compatible Windows Server 2012 [aplicaciones de escritorio | Aplicaciones para UWP]
Plataforma de destino Windows
Encabezado processthreadsapi.h (incluya Windows.h)
Library Kernel32.lib
Archivo DLL Kernel32.dll

Vea también

Función GetProcessInformation, función SetThreadInformation, estructura MEMORY_PRIORITY_INFORMATION, función SetProcessInformation, enumeración PROCESS_INFORMATION_CLASS, estructura OVERRIDE_PREFETCH_PARAMETER