在 C 中更改当前进程的优先级

标签 c unix cross-platform process-management

在 Windows 上我可以做:

HANDLE hCurrentProcess = GetCurrentProcess();

SetPriorityClass(hCurrentProcess, ABOVE_NORMAL_PRIORITY_CLASS);

我怎样才能在 *nix 上做同样的事情?

最佳答案

尝试:

#include <sys/time.h>
#include <sys/resource.h>

int main(){
    setpriority(PRIO_PROCESS, 0, -20);
}

请注意,您必须以 super 用户身份运行才能运行。

(有关更多信息,请在提示符下键入“man setpriority”。)

关于在 C 中更改当前进程的优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29621/

相关文章:

c - 在 cmake 文件的 execute_process 命令中使用 cmake 变量

c - 如何使用 openssl API 读取 DER 格式的服务器证书?

java - r 软件代码签名 java 跨平台游戏

python - 为网络和桌面创建应用程序

sockets - 为什么可以使用unix域套接字将fd从 child 转移到父亲?

unix - 为什么 `nm` 实用程序如此命名?

python - 当另一个 python 脚本正在运行时,如何停止我的 python 脚本?

c - 如何仅使用 sscanf 从字符串中提取所有数字?

c++ - 如何让用户使用 openAL 选择录音设备?

c - 如何将此 C 代码转换为 MIPS 汇编代码