1

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.

andy
  • 3,951
  • 9
  • 29
  • 40

1 Answers1

3

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.

Guntram Blohm
  • 9,667
  • 2
  • 24
  • 31
  • so does you mean that any porcess run at priority below zero? Do you have any canonical link about it? – andy Mar 01 '14 at 13:31
  • 1
    Added some examples. Be careful with "priority below zero", a process that gets less CPU is "nice" to other processes, i.e. has a HIGHER nice value. So, a process will get more CPU if it has a LOWER number in the NI column. – Guntram Blohm Mar 01 '14 at 13:58
  • Sorry for my wrong undersatanding and your example is very comprehensive. Thanks. – andy Mar 02 '14 at 01:31