Is nice command a myth?

Hello,

Some guy said to me that using the nice command to decrease the priority of a process is a myth, that the operating system corrects the priorities as the processes need cpu. Is this true?

nice changes base priority. Unless you are superuser, it only decreases your priority relative to other processes on the system.

Note: Priority numbers are backwards, higher priority number == lower priority

The OS scheduler can change (up or down) priority. However if your base priority is lower than everyone else logged on, a temporary boost will still have you below the "crowd". ALL non-realtime processes can have process priority changed for a lot of reasons. This is normal.

No way is nice a "myth".

Jim is absolutely correct. Additionally keep in mind that priorities are relative numbers. There are only so many CPU ticks to distribute among processes and if every process has a high priority then every one might get the same amount as if every process has a low priority, as far as these priorities are equal.

I hope this helps.

bakunin

Actually, this is true, but nice priorities still come into play. The longer a process has been running and consuming CPU resources, the lower a priority it gets. The more time it's been in the run queue without having had a chance to execute, the higher priority it gets. These mechanisms are meant to ensure fairness and reduce "starvation". Nice affects starting priorities, and only after a very long runtime, will the nice level for a particular process become irrelevant.

At any rate, task scheduling is OS-dependent. The Linux 2.6 kernel uses something called the Completely Fair Scheduler. From the author, this quote might be relevant:

The nice command breaks ties between processes that would otherwise be treated identically by the kernel. And it only effects processes while they are cpu bound. If a process is waiting for I/O to complete, it must wait regardless of how little niceness it has.

But I am a little tempted to rewrite readline to check the nice value. If the process has negative niceness, it would wait 5 seconds then issue a hurry-up message.... "Hey! Let's speed it up! I don't have all day!" :smiley: