网站首页  词典首页

请输入您要查询的函数:

 

术语 setpriorityclass
释义 SetPriorityClass
语法:
C++
BOOL WINAPI SetPriorityClass(
__in HANDLE hProcess,
__in DWORD dwPriorityClass
);
SetPriorityClass函数
设置指定进程的优先级。这与每个进程的线程的优先级值的值一起确定每个线程的基本优先级的Level。
参数
hProcess [in]
句柄的进程。
句柄必须有PROCESS_SET_INFORMATION访问权限。有关更多信息,请参见过程的安全性和访问权限。
dwPriorityClass [in]
该进程的优先级。此参数可以是下列值之一。
PriorityMeaning
ABOVE_NORMAL_PRIORITY_CLASS
0x00008000Process已超过NORMAL_PRIORITY_CLASS,但低于HIGH_PRIORITY_CLASS优先。
BELOW_NORMAL_PRIORITY_CLASS
0x00004000Process已超过IDLE_PRIORITY_CLASS但低于NORMAL_PRIORITY_CLASS优先。
HIGH_PRIORITY_CLASS
0x00000080Process的执行时间,必须立即执行的重要任务。该进程的线程优先于正常或空闲优先级进程的线程。一个例子是任务列表,它必须迅速作出反应时,由用户要求,不论在操作系统上的负载。使用时小心使用高优先级,因为高优先级的应用程序可以使用几乎所有可用的CPU时间。
IDLE_PRIORITY_CLASS
0x00000040Process的线程运行只有当系统处于闲置状态。该进程的线程抢占以任何在较高优先级的线程正在运行的进程。一个例子是一个屏幕保护程序。空闲优先类是继承的子进程。
NORMAL_PRIORITY_CLASS
0x00000020Process没有特别安排的需要。
PROCESS_MODE_BACKGROUND_BEGIN
0x00100000Begin后台处理模式。该系统降低了该进程(和它的线程),使资源调度优先级,它可以在没有任何显着影响在前台活动的背景工作。
此值可以指定只有hProcess是一个句柄到当前进程。函数失败如果进程已经在后台处理模式。
Windows Server 2003和Windows XP/2000操作系统:此值不支持。
PROCESS_MODE_BACKGROUND_END
0x00200000End后台处理模式。该系统恢复进程(及其线程),因为他们之前的进程进入后台处理模式是资源调度优先级。
此值可以指定只有hProcess是一个句柄到当前进程。函数失败如果过程不是在后台处理模式。
Windows Server 2003和Windows XP/2000操作系统:此值不支持。
REALTIME_PRIORITY_CLASS
0x00000100Process具有最高的优先事项。该进程的线程优先于所有其他进程的线程包括操作系统,程序执行重要任务。例如,一个实时的过程,比一个很短的时间间隔执行可能会导致更多的磁盘高速缓存不刷新或导致鼠标不响应。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
备注
每个线程都有一个基本优先级的线程的优先级值和其进程的优先级确定。该系统使用的所有可执行线程的基本优先级的Level,以确定哪个线程获取未来的CPU时间片。该SetThreadPriority功能,可以设置线程的优先级的基础相对于它的进程的优先级。有关更多信息,请参阅调度优先级。
* _PRIORITY_CLASS值的影响进程的CPU调度优先级。对于执行过程,如背景工作文件I / O,网络的I / O,或数据处理,它是不够的调整CPU调度优先级,甚至连一个空闲CPU优先过程可以方便地与系统响应干扰时,使用磁盘和内存。进程执行后台工作应该使用PROCESS_MODE_BACKGROUND_BEGIN和PROCESS_MODE_BACKGROUND_END值,以调整其资源调度的优先事项;过程与用户交互不应使用PROCESS_MODE_BACKGROUND_BEGIN。
如果一个过程是在后台处理模式,它创建也将在后台处理模式,新的线程。当一个线程在后台处理模式时,它应尽量共享,例如关键部分,堆资源,并在此过程中的其他线程处理,否则可能会出现优先级倒置。如果有高优先级的线程,在后台处理模式线程执行可能无法及时安排,但它永远不会饿死。
每个线程可以进入后台处理模式下独立使用SetThreadPriority。不要调用SetPriorityClass进入后,在进程中的线程后台处理模式称为SetThreadPriority进入后台处理模式。进程结束后,后台处理方式,它重置在这一过程中的所有线程,但它是不知道该进程的线程可能已经在后台处理模式。
实例
下面的示例演示的过程中背景模式的使用。
#include
#include
void main()
{
DWORD dwError, dwPriClass;
if(!SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_BEGIN))
{
dwError = GetLastError();
if( ERROR_PROCESS_MODE_ALREADY_BACKGROUND == dwError)
printf("Already in background mode\\n");
else printf("Failed to enter background mode (%d)\\n", dwError);
goto Cleanup;
}
// Display priority class
dwPriClass = GetPriorityClass(GetCurrentProcess());
printf("Current priority class is 0x%x\\n", dwPriClass);
//
// TODO: Perform background work
//
;
if(!SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_END))
{
printf("Failed to end background mode (%d)\\n", GetLastError());
}
Cleanup:
// TODO: Clean up
;
}
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
CreateProcess的
CreateThread
GetPriorityClass
GetThreadPriority
进程和线程函数
过程
调度优先级
SetThreadPriority
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==SetPriorityClass Function
Sets the priority class for the specified process. This value together with the priority value of each thread of the process determines each thread's base priority level.
Syntax
C++
BOOL WINAPI SetPriorityClass(
__in HANDLE hProcess,
__in DWORD dwPriorityClass
);
Parameters
hProcess [in]
A handle to the process.
The handle must have the PROCESS_SET_INFORMATION access right. For more information, see Process Security and Access Rights .
dwPriorityClass [in]
The priority class for the process. This parameter can be one of the following values.
PriorityMeaning
ABOVE_NORMAL_PRIORITY_CLASS
0x00008000Process that has priority above NORMAL_PRIORITY_CLASS but below HIGH_PRIORITY_CLASS.
BELOW_NORMAL_PRIORITY_CLASS
0x00004000Process that has priority above IDLE_PRIORITY_CLASS but below NORMAL_PRIORITY_CLASS.
HIGH_PRIORITY_CLASS
0x00000080Process that performs time-critical tasks that must be executed immediately. The threads of the process preempt the threads of normal or idle priority class processes. An example is the Task List, which must respond quickly when called by the user, regardless of the load on the operating system. Use extreme care when using the high-priority class, because a high-priority class application can use nearly all available CPU time.
IDLE_PRIORITY_CLASS
0x00000040Process whose threads run only when the system is idle. The threads of the process are preempted by the threads of any process running in a higher priority class. An example is a screen saver. The idle-priority class is inherited by child processes.
NORMAL_PRIORITY_CLASS
0x00000020Process with no special scheduling needs.
PROCESS_MODE_BACKGROUND_BEGIN
0x00100000Begin background processing mode. The system lowers the resource scheduling priorities of the process (and its threads) so that it can perform background work without significantly affecting activity in the foreground.
This value can be specified only if hProcess is a handle to the current process. The function fails if the process is already in background processing mode.
Windows Server 2003 and Windows XP/2000: This value is not supported.
PROCESS_MODE_BACKGROUND_END
0x00200000End background processing mode. The system restores the resource scheduling priorities of the process (and its threads) as they were before the process entered background processing mode.
This value can be specified only if hProcess is a handle to the current process. The function fails if the process is not in background processing mode.
Windows Server 2003 and Windows XP/2000: This value is not supported.
REALTIME_PRIORITY_CLASS
0x00000100Process that has the highest possible priority. The threads of the process preempt the threads of all other processes, including operating system processes performing important tasks. For example, a real-time process that executes for more than a very brief interval can cause disk caches not to flush or cause the mouse to be unresponsive.

Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError .
Remarks
Every thread has a base priority level determined by the thread's priority value and the priority class of its process. The system uses the base priority level of all executable threads to determine which thread gets the next slice of CPU time. The SetThreadPriority function enables setting the base priority level of a thread relative to the priority class of its process. For more information, see Scheduling Priorities .
The *_PRIORITY_CLASS values affect the CPU scheduling priority of the process. For processes that perform background work such as file I/O, network I/O, or data processing, it is not sufficient to adjust the CPU scheduling priority; even an idle CPU priority process can easily interfere with system responsiveness when it uses the disk and memory. Processes that perform background work should use the PROCESS_MODE_BACKGROUND_BEGIN and PROCESS_MODE_BACKGROUND_END values to adjust their resource scheduling priorities; processes that interact with the user should not use PROCESS_MODE_BACKGROUND_BEGIN.
If a process is in background processing mode, the new threads it creates will also be in background processing mode. When a thread is in background processing mode, it should minimize sharing resources such as critical sections, heaps, and handles with other threads in the process, otherwise priority inversions can occur. If there are threads executing at high priority, a thread in background processing mode may not be scheduled promptly, but it will never be starved.
Each thread can enter background processing mode independently using SetThreadPriority. Do not call SetPriorityClass to enter background processing mode after a thread in the process has called SetThreadPriority to enter background processing mode. After a process ends background processing mode, it resets all threads in the process; however, it is not possible for the process to know which threads were already in background processing mode.
Examples
The following example demonstrates the use of process background mode.
#include
#include
void main()
{
DWORD dwError, dwPriClass;
if(!SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_BEGIN))
{
dwError = GetLastError();
if( ERROR_PROCESS_MODE_ALREADY_BACKGROUND == dwError)
printf("Already in background mode\\n");
else printf("Failed to enter background mode (%d)\\n", dwError);
goto Cleanup;
}
// Display priority class
dwPriClass = GetPriorityClass(GetCurrentProcess());
printf("Current priority class is 0x%x\\n", dwPriClass);
//
// TODO: Perform background work
//
;
if(!SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_END))
{
printf("Failed to end background mode (%d)\\n", GetLastError());
}
Cleanup:
// TODO: Clean up
;
}
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
CreateProcess
CreateThread
GetPriorityClass
GetThreadPriority
Process and Thread Functions
Processes
Scheduling Priorities
SetThreadPriority
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms686219(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:15:55