Follow the Australian Telecommunications scene NEWSLETTER- FREE TRIAL
The Linux distillery
Bringing the world of Linux to you, David cuts through the tech and shows you how it works and how to use it, in terms that apply to any distro. RSS
Technology news and Jobs arrow The Linux distillery arrow The nuts and bolts of the Linux process scheduler
The nuts and bolts of the Linux process scheduler E-mail
by David M Williams   
Monday, 18 February 2008
Use the up arrow and enter to call ps repeatedly over a period of several seconds. You’ll see very soon that the priority – the PRI column – changes value for both scripts. The priority for yielder.sh increases and the priority for preempter.sh decreases. This is because the scheduler is giving a positive and a negative bonus respectively.

Without running anything else, these two processes will settle down to a point where their bonus values no longer change. On a busy server the bonuses may continue fluctuating as other processes also start and terminate.

Immediately, you will realise that the cards are against you if you genuinely want your system to give its utmost to your complex calculations. On the one hand, there’s a reason for this: Linux wants to ensure performance isn’t degraded for anyone using the system interactively. On the other hand, it’s your system. It should do what you want.

And make it do what you want you can. You can directly influence the scheduler’s decisions through another value, called the nice value. This is so called because it lets you be “nice” to other tasks on the system. Give a process a positive nice value, and it will have a lower overall priority. By contrast, give it a negative nice value and the scheduler will boost its priority higher. Only the super user can assign a negative nice value; the only thing non-privileged users may do is bump their own processes lower down the queue.

Re-run the preempter.sh process with a negative nice value like so:

sudo nice –n -5 ./preempter.sh &

Check out its effective priority via the same ps command as above and compare to the previous set of results.
Once a nice value has been set it is fixed for the lifetime of the process unless you alter it with a command called renice; apart from this nothing else can influence it. Use renice to modify the nice value of an existing process with a command like this:

sudo renice -10 –p 50432

(where 50432 is the process ID, or pid, of the process we want to renice.) The command will tell you the previous priority and the new priority.

Once again, unprivileged users may only increase the nice value; they cannot drop it down again even if it already was a positive value.

Now for something different: everything applies to “normal” processes. There’s something which has not been discussed and that is critical real-time applications which absolutely must guarantee the software responds to events within a certain interval of time after an event. Medical applications that interact with life monitoring hardware are but one example; if the application isn’t running when it should be then lives could be lost.

The Linux scheduler provides a range of priority levels dedicated to real-time applications which are not ordinarily available. The command chrt can launch such applications. As they have a priority out of the range of normal apps they are guaranteed to run frequently. It’s also worth noting real-time processes don’t have nice values or bonus values; their process is fixed to one value forever.

Come back next time and I’ll tell you more about Linux processes including how to tweak the kernel to suit your particular multitasking needs.

Powered By Joomla Tags

Please enable JavaScript in your browser to post your comment!



 
< Next story in category   Previous story in the category >
iTWire user statistics Visitors last 30 days
694,279
Subscribers 15,210
#1 independent technology news advertise here
  •   *  
  • Search
  • AdvSeach
  • Login
  • Events
  • FreeStuff

- Advertisement -

Featured Whitepapers

Follow iTWire on Twitter

About iTWire

iTWire is all about technology news, information, jobs and community for the IT and telecommunications industry professional. Subscribe to our free ICT daily newsletter