top中显示的ni值表示进程当前的nice值,nice值会影响到进程的pr(调度优先级),pr越小越优先调度,当nice值为负数的时候,优先级会变高。写python程序做下面测试可以看到当nice值会正时,ni显示nice值为正的process所消耗的cpu。可以通过renice命令进行调整nice值,调整nice值为0或者负数,ni转化成us进程测试while True:
passrenice 5 -p 9144Cpu(s): 0.0%us, 0.3%sy, 99.7%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%strenice 0 -p 9144Cpu(s): 99.3%us, 0.3%sy, 0.3%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%strenice -5 -p 9144Cpu(s): 94.7%us, 5.3%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st线程测试主线程的nice值改变,老的线程是不变的,ni值依旧。#/usr/bin/python
import threading
class myThread(threading.Thread):
def __init__(
...
继续阅读
(14)