13

Some processes spend most of their "lives" in a sleep status. Daemons, servers and general listener come to mind. I was wondering if they get the same CPU time in that state? On something like my laptop, that wouldn't be very optimal!

I vaguely remember from my operating system course that there are different approaches to scheduling. I am interested to find out more about my current Linux (Debian) box.

How can I find out about my current scheduling policies? Can I change them dynamically? With a pretty userland app?

2 Answers 2

17

Processes do not consume CPU resources while they are sleeping. They may add some overhead since the Kernel has to juggle them around, but that is very insignificant.

However, because of the way the question is worded, I should mention that when using Linux's CFS (Completely Fair Scheduler), it attempts to give programs increased CPU time in proportion to the time it sleeps - that is, if a process sleeps a lot, when it is resumed, it gets a higher priority.

See http://www.ibm.com/developerworks/linux/library/l-completely-fair-scheduler/ for a description of CFS.

0
4

By definition, a sleeping process is not executing on the cpu, so obviously the amount of cpu time it is using is zero.

2
  • 1
    If that is true, how does the machine know when the sleep time is complete and that it should restart the execution?
    – Dave Sims
    Commented Apr 3, 2020 at 18:37
  • @DaveSims the sleep time can be definite and handled by the kernel but most of the cases is indefinite. The process status is moved to running and the process data moved back on the CPU only when some specific event occurs. Interrupts are intended for this purpose. If you need more details you can find then in the book "Operating Systems" by William Stallings or "Modern Operating Systems" by Andrew Tanenbaum.
    – Bemipefe
    Commented Sep 27, 2021 at 10:58

You must log in to answer this question.

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