Bear in mind that "load" simply tells you how many processes are waiting for a time slot with work to do. If you want to see how much time is being spent on the CPU you will have to look elsewhere. The reality is that linux process accounting is weak - mpstat is probably the best way to see how busy a core is but it has serious limitations. It will at least tell you how much time is spent in user/system execution (application vs. kernel). In a very busy platform much time can be spent context switching as a result of locking calls, IO and interrupts. The task scheduler in the OS (linux) uses a number of measures to determine when a process must yield - most often this is a measure of time. Once a process has spent its quantum on the core it gets suspended and the context is switched to the next process (or to the kernel). A process that does something like a blocking IO call tells the scheduler that it will not have useful work to do until IO is needed and that process will then yield immediately, maybe before is time is up. There are a number of nuances and quid pro quos and exceptions, but fundamentally the On Wed, Oct 10, 2012 at 9:39 AM, Manu Abraham wrote= : > On Wed, Oct 10, 2012 at 6:49 PM, V G wrote: > > Hi all, I have a question about CPU load, task scheduling, and how a re= al > > operating system (like Linux/BSD/QNX) manage threads. > > > > Q: If you write a simple, single-threaded program in C as follows > > > > int main() { while(1); } > > > > and run it on a single core CPU, the CPU load shoots up to 1.00 and sta= ys > > there. Makes sense, as all of the CPU time is spent in this thread. (Al= l > as > > in almost all, since the operating system's task scheduler and other > > processes have to run as well.) > > > What you have done is a busy loop, CPU spends all the time in there. > > > > However, many single threaded network event loop libraries, as well as > GUI > > libraries come with their own main loop/event loop. Your program will > never > > exit from the main loop unless you kill it, but while the program is > > running, the CPU does NOT appear to be under load. What's going on here= ? > > How is it that the main loop is running and is responsive, yet the CPU = is > > under minimal load? > > generally they make use of poll/select > http://www.makelinux.net/ldd3/chp-6-sect-3 > > or use a thread instead > http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 Glen Wiley "A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away." - Antoine de Saint-Exupery --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .