A daemon does not just run an infinite loop, it calls to operating system and asks “put me to sleep until X happens”. The OS then marks the process as “sleeping” and does not run it’s code anymore. If all processes are asleep, OS issues a HALT command to the CPU, making it power down until something happens or the timer runs out.
Then the X happens, OS will walk the list of waiting processes and mark them as “running” again. That means, they will get CPU time when their turn comes up.
Note: the only time the CPU usage <100% is then *all* processes are asleep! If even one is awake, it alone will get all 100% of CPU! That’s why your “busy-waiting” process makes CPU usage 100% – it never goes to sleep.
Latest Answers