Search code examples
c++linuxprocessposix

Does linux c/c++ programming support setting process priority?


Under linux, I can use "nice" command to set process priority, NP. But I didn't find a way to set this information within my c program, I don't find clue in [APUE] book.

Is there a posix api to do this job? Thanks a lot.


Solution

  • There is nice() function in unistd.h.

    Example :

    #include <unistd.h>
    
    int main()
    {
        nice(4); // To set level 4 as nice value to current process
        return 0;
    }