- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2019-05-30T11:32:17+09:00","default:honma","honma")
* nice値の設定 [#d8aa1fe1]
参考:[[NICE:http://linuxjm.osdn.jp/html/LDP_man-pages/man2/nice.2.html]], [[GETPRIORITY:http://linuxjm.osdn.jp/html/LDP_man-pages/man2/getpriority.2.html]]
#highlight(c){{
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <errno.h>
void getprio(void)
{
int ret = 0;
errno = 0;
ret = getpriority(PRIO_PROCESS, 0);
if (errno == 0) {
printf("priority = %d\n", ret);
}
else {
perror("getpriority");
}
}
int main(int argc, char **argv)
{
int ret = 0;
getprio();
/* キー入力待ち */
getchar();
/* nice値の設定 */
errno = 0;
ret = nice(-1);
if (errno == 0) {
printf("priority = %d\n", ret);
}
else {
perror("nice");
}
/* キー入力待ち */
getchar();
getprio();
return 0;
}
}}
#highlight(end)
[[ソースコード:http://www.chobits.com/pukiwiki/index.php?plugin=attach&pcmd=open&file=sched_get_prio.c&refer=sched_getattr]]
実行結果
$ sudo ./getprio
[sudo] ****** のパスワード:
priority = 0
priority = -1
priority = -1
別ターミナルから確認
$ cat /proc/`pidof getprio`/sched | grep -e policy -e prio
getprio (96338, #threads: 1)
policy : 0
prio : 120
$ cat /proc/`pidof getprio`/stat | awk -F' ' '{print $18,$19}'
20 0
※ priority を -1 に設定後、確認
$ cat /proc/`pidof getprio`/sched | grep -e policy -e prio
getprio (96338, #threads: 1)
policy : 0
prio : 119
$ cat /proc/`pidof getprio`/stat | awk -F' ' '{print $18,$19}'
19 -1
$