Linux下C语言中的nice函数

本文最后更新于2017年8月5日,已超过 1 年没有更新,如果文章内容失效,还请反馈给我,谢谢!

=Start=

缘由:

学习需要

正文:

参考解答:
#include <stdio.h>    /* printf */
#include <stdlib.h>   /* atoi, system, exit */
#include <errno.h>    /* errno */
#include <string.h>   /* strerror */
#include <unistd.h>   /* nice */
int main(int argc, char const *argv[])
{
    int adjustment = 0;
    if ( argc > 1 ) {
        adjustment = atoi( argv[1] );
    }
    errno = 0;
    int ret;
    ret = nice( adjustment );
    printf( "nice(%d):%d\n", adjustment, ret );
    if ( -1 == ret && errno) {
        if ( errno == EACCES ) {
            printf( "Cannot set priority:%s./n", strerror( errno ) );
            exit(-1);
        }
    }
    sleep(10);
    system("nice");
    return 0;
}

&

for i in {1..5}; do
    ps aux | grep --color "a.out"
    sleep 2
done
参考链接:

https://linux.die.net/man/3/nice

Linux C语言库函数参考 — nice
http://blog.csdn.net/thinkerabc/article/details/746764

C语言nice()函数:改变进程优先顺序
http://c.biancheng.net/cpp/html/283.html

Difference between nice and setpriority in unix
https://stackoverflow.com/questions/7618291/difference-between-nice-and-setpriority-in-unix

=END=

声明: 除非注明,ixyzero.com文章均为原创,转载请以链接形式标明本文地址,谢谢!
https://ixyzero.com/blog/archives/3490.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注