- 论坛徽章:
- 2
|
本帖最后由 cdsfiui 于 2017-01-10 14:50 编辑
很简单的一段代码:
#include<unistd.h>
#include<sys/resource.h>
#include<sys/syscall.h>
#include<sys/types.h>
#include<stdio.h>
int main()
{
int i=0;
pid_t pid=getpid();
pid_t tid=syscall(SYS_gettid);
printf("%d,%d\n",pid,tid);
setpriority(PRIO_PROCESS,0,-2);
while(true){
++i;
}
return 0;
}
setpriority函数调用的时候,第二个参数填0,指代当前进程。这个是根据man文档来的:
The value which is one of PRIO_PROCESS, PRIO_PGRP, or PRIO_USER, and
who is interpreted relative to which (a process identifier for
PRIO_PROCESS, process group identifier for PRIO_PGRP, and a user ID for
PRIO_USER). A zero value for who denotes (respectively) the calling
process, the process group of the calling process, or the real user ID
of the calling process. Prio is a value in the range -20 to 19 (but
see the Notes below). The default priority is 0; lower priorities
cause more favorable scheduling.
编译运行后,我看top命令中,a.out的PR仍然是默认的20,没有我期待的-2变成了18
这是为什么,拿到我的setpriority没有起作用吗?
|
|