在C更改自己的进程优先级 [英] Change own process priority in C

查看:241
本文介绍了在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.

(在提示更多信息,键入人setpriority')

(for more info, type 'man setpriority' at a prompt.)

这篇关于在C更改自己的进程优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆