unix中nice和setpriority的区别
我正在尝试在 C 中实现 unix 的“nice”命令的不同风格。我已经看到了 Nice() 系统调用和 setpriority() 调用的定义。 Nice() 调用仅增加/减少进程的优先级。如果我想将进程的优先级设置为特定值,我不能使用nice()调用吗?基本上,除了如何修改优先级之外,nice() 和 setpriority() 之间还有什么区别吗?
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() ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是历史性的。
nice()
早在setpriority()
之前就被引入了。为了向后兼容,保留了nice
函数。It's historical.
nice()
was introduced long beforesetpriority()
. For backwards compatibility, thenice
function was retained.nice
设置您自己的优先级(当前进程的良好程度)。setpriority
允许您设置其他进程(或进程组或用户)的优先级。将其视为renice
。男人3p不错
man 3p 设置优先级
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 asrenice
.man 3p nice
man 3p setpriority
nice()
修改当前进程相对于其当前nice值的nice值,因此进程不需要知道其起始nice值,它只关心它应该比当前nice值更好系统(例如:一个进程启动一个进行一些后台处理的子进程,该子进程将自己设置为良好)。setpriority()
用例是用户向特定进程显式设置绝对好值。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.