在C中更改当前进程的优先级 [英] Change priority of the current process in C
本文介绍了在C中更改当前进程的优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Windows上我可以这样做:
On Windows I can do:
HANDLE hCurrentProcess = GetCurrentProcess();
SetPriorityClass(hCurrentProcess, ABOVE_NORMAL_PRIORITY_CLASS);
我如何在* nix上做同样的事情?
How can I do the same thing on *nix?
推荐答案
尝试:
#include <sys/time.h>
#include <sys/resource.h>
int main(){
setpriority(PRIO_PROCESS, 0, -20);
}
请注意,您必须以超级用户身份运行才能正常工作。
Note that you must be running as superuser for this to work.
(有关更多信息,请在提示符后键入 man setpriority。)
(for more info, type 'man setpriority' at a prompt.)
这篇关于在C中更改当前进程的优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文