I googled the iostat command's man manual about the %nice. In the explanation of the value of %nice there is a phrase about nice priority. I can not understand the meaning about it, can someone explain it?

The complete comment in the man page is as follows.

%nice

Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.

有帮助吗?

解决方案

It means processes that have been started with the nice command, or have called nice/setpriority to lower their priority below the standard one. (nice was the name of the system call in older unixes as well, it's been replaced by setpriority now. The command name is still the same).

See the manual page or documentation for /proc/stat, for example, http://www.mjmwired.net/kernel/Documentation/filesystems/proc.txt.

Or, try it yourself (on an otherwise unloaded system that belongs to you!). Open 2 terminals. In the 1st, type

$ perl -e 'print "$$\n"; for (;;){}'

and remember the pid, then in the second

$ ps -l -p <pid>
$ iostat -c 1 5

Then, stop the process in the 1st terminal, and restart it with lower priority:

$ nice -1 perl -e 'print "$$\n"; for (;;){}'

Output, on my system: (first time)

$ perl -e 'print "$$\n"; for (;;){}'
22482
$ ps -l -p 22482
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 R  1000 22482 22443 99  80   0 -  4279 -      pts/1    00:00:16 perl
$ iostat -c 1 5
...
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
         100.00    0.00    0.00    0.00    0.00    0.00

(With nice)

$ nice -1 perl -e 'print "$$\n"; for (;;){}'
22666
$ ps -l -p 22666
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 R  1000 22666 22443 99  81   1 -  4279 -      pts/1    00:00:06 perl
$ iostat  -c 1 5
...
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.00  100.00    0.00    0.00    0.00    0.00

The nice -1 command causes the NI column to increase by one; at the same time, the 100% CPU usage (that is caused by the perl command) moves from %user to %nice.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top