Difference between nice and setpriority in unix

假如想象 提交于 2019-12-09 10:14:45

问题


I'm trying to implement a different flavor of the 'nice' command of unix in C. I have seen the definitions of nice() system call and setpriority() call. The nice() call only increments/decrements the priority of the process. If I want to set the priority of a process to a particular value, can't I use the nice() call? Basically, other than how the priority is modified, is there any difference between nice() and setpriority() ?


回答1:


It's historical. nice() was introduced long before setpriority(). For backwards compatibility, the nice function was retained.




回答2:


nice sets your own priority (the niceness of the current process). setpriority lets you set the niceness of other processes (or process groups or users). Think of it as renice.

man 3p nice

int nice(int incr);

man 3p setpriority

int setpriority(int which, id_t who, int value);




回答3:


nice() modifies the nice value of the current process relative to its current nice value, so the process doesn't need to know about its starting nice value, it only cares that it should be nicer to the system (e.g: a process launches a child who does some background processing, the child sets itself to be nice).

setpriority() use case is the user explicitly setting absolute nice values to specific processes.



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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!