19

According to the man page, and wikipedia; nice ranges from -20 to 20.

Yet when I run the following command, I find some processes have a non numerical value such as (-). See the sixth column from the left with title 'NI'.

What does a niceness of (-) indicate?

 ps axl 
 F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0     1     0  20   0  19356  1548 poll_s Ss   ?          0:00 /sbin/init
1     0     2     0  20   0      0     0 kthrea S    ?          0:00 [kthreadd]
1     0     3     2 -100  -      0     0 migrat S    ?          0:03 [migration/0]
1     0     4     2  20   0      0     0 ksofti S    ?          0:51 [ksoftirqd/0]
1     0     5     2 -100  -      0     0 cpu_st S    ?          0:00 [migration/0]
5     0     6     2 -100  -      0     0 watchd S    ?          0:09 [watchdog/0]
1     0     7     2 -100  -      0     0 migrat S    ?          0:08 [migration/1]
1     0     8     2 -100  -      0     0 cpu_st S    ?          0:00 [migration/1]
1     0     9     2  20   0      0     0 ksofti S    ?          1:03 [ksoftirqd/1]
5     0    10     2 -100  -      0     0 watchd S    ?          0:09 [watchdog/1]
1     0    11     2 -100  -      0     0 migrat S    ?          0:05 [migration/2]

I've checked 3 servers running: Ubuntu 12.04 and CentOs 6.5 and Mac OsX 10.9. Only the Ubuntu and CentOs machines have non digit niceness values.

1
  • FYI: All of those processes whose names are in [brackets] are actually kthreads (kernel threads). Commented May 1, 2014 at 5:06

2 Answers 2

18

What does a niceness of (-) indicate?

Notice those also have a PRI score of -100; this indicates the process is scheduled as a realtime process. Realtime processes do not use nice scores and always have a higher priority than normal ones, but still differ with respect to one another.

You can view details per process with the chrt command (e.g. chrt -p 3). One of your -100 ones will likely report a "current scheduling priority" of 99 -- unlike nice, here high values are higher priority, which is probably where top created the -100 number from. Non-realtime processes will always show a "current scheduling priority" of 0 in chrt regardless of nice value, and under linux a "current scheduling policy" of SCHED_OTHER.

Only the Ubuntu and CentOs machines have non digit niceness values.

Some versions of top seem to report realtime processes with rt under PRI and then 0 under NI.

1
  • Wonderful answer. I knew it had something to do with -100 but couldn't figure it out :)
    – Ramesh
    Commented Apr 30, 2014 at 16:17
7

@Goldlilock's answer directed me to do the research in the right path. This is my research details.

Scheduling Algorithms available for processes

Linux supports 3 scheduling policies. SCHED_FIFO, SCHED_RR, and SCHED_OTHER. SCHED_OTHER is the default universal time-sharing scheduler policy used by most processes; SCHED_FIFO and SCHED_RR are intended for special time-critical applications that need precise control over the way in which runnable processes are selected for execution.

Priorities available

In order to select a process to run, the Linux scheduler must consider the priority of each process. Actually, there are two kinds of priority.

A static priority value is assigned to each process and scheduling depends on this static priority. Processes scheduled with SCHED_OTHER have static priority 0; processes scheduled under SCHED_FIFO or SCHED_RR can have a static priority in the range 1 to 99(99 is the highest).

The sys_sched_get_priority_max( ) routine returns the static priority of the process, it returns 0 for non-realtime processes.

Dynamic priority is used for non-real time applications.

All real-time processes are at a higher priority than normal processes. Linux implements real-time priorities in accordance with POSIX. The below graph might give an overview of how the processes are scheduled with their priorities.

HIGH PRIORITY – - – - – > – - – - – > – - – - – > – - – - – > – - – – LEAST PRIORITY
……..real time priority (static priority)…….| …. nice value (dynamic priority) …..
99 ……………………….. 50 ……………………… 1 | -20 …….. -10 …….. 0 …….. 10 ……. 19

Now, we can issue the below command to check the real time priority of a process. Here I am using watchdog since it had a nice value listed as -.

ps -e -o class,rtprio,pri,nice,cmd | grep watchdog

This is the above command's output. As we can see the realtime priority is 99 which is the highest possible priority.

FF      99 139   - [watchdog/0]
FF      99 139   - [watchdog/1]
TS       -  21   0 grep watchdog

So as per my understanding the real time priority can take a maximum value of 99 and so there can not be any nice value over it. That is the reason, we get the nice output as - for watchdog and other system processes.

References

http://oreilly.com/catalog/linuxkernel/chapter/ch10.html http://atipaday.wordpress.com/2008/08/19/atad-21-linux-process-priority-range/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .