What does CPU usage for a process actually mean

23,564

CPU usage is computed by the operating system's process/task scheduler. Indeed, if a CPU usage is 10%, that indicates that the task is actively running for 10% of the task scheduler's unit periods; other programs may run in the remaining 90% CPU time, or the OS will simply idle. Likewise, if the total CPU usage for all programs is 10%, that indicates that no programs on the system are being executed 90% of the time.

Since no programs run on the "bare metal" in a multitasked operating system (like Windows or Linux), CPU usage is a measure of what percentage your CPU's cycles are dedicated to running that one particular program. This is why if you have an infinite loop in a program, even though no "work" is being done, the CPU usage still approaches 100% (as the program is attempting to use every scheduling period offered to it by the operating system to execute some code).

Although processes are always running, they don't use 100% of the CPU in most cases since a process can wait for a particular event/interrupt to occur, or have indicated to the operating system to suspend/sleep its' operation for a short amount of time.

Share:
23,564

Related videos on Youtube

Dave Stibrany
Author by

Dave Stibrany

Updated on September 18, 2022

Comments

  • Dave Stibrany
    Dave Stibrany over 1 year

    Assume the computer has a single core - what exactly does it mean for process A to be running at 100% CPU capacity vs (lets say) 10% CPU capacity.

    If the CPU was 2.0 GHz, does that mean in a time slice for process A, that the processor was executing 2 billion steps per second (if at 100% cap), but would only be executing 200 million steps (if at 10% cap)?

    What would cause the 100% scenario vs the 10% scenario?

    • Ramhound
      Ramhound over 10 years
      The different between 10% usage and 100% usage is clear. In one case the task in question is taking 10% of the executing capabilities. In other words everytime the clock is trigged, 10% of the execution time, is assigned to that process. Likewise 100% usage means 100% of the execution time is assigned to that process ( i.e. no other proceses tasks are able execuate ) thus creating a deadlock situation. My example uses a single process to make the process of the CPU running a task easier to understand.
    • Dave Stibrany
      Dave Stibrany over 10 years
      When you say 'everytime the clock is triggered', is that the same thing as a time slice or is that an actual tick of the CPU?
    • Ramhound
      Ramhound over 10 years
      @DaveStibrany - Lets say you have a 2Ghz Intel CPU. This means that everytime the clock signal is triggered the CPU will process X x86 operation instructions. How many insructions are actually performed depends on several different things. If you have a 2-core x86 CPU it means that you can perform 2 seperate instructions in the same amount of time. This means either 2 different processes have equal priority or a single process can perform an instruction twice as fast ( requires you to write said operation in a certain way in order to do so ).
    • Ramhound
      Ramhound over 10 years
      A great starting point to understand what actually happens during a clock cycle is to learn the x86 assembly language. Once you do that you understand what an instruction is.
  • Ramhound
    Ramhound over 10 years
    @Breakthrough - What do you consider 'bare metal" because I have always considered that to be a program written in assembly language and you certainly can do that.
  • Breakthrough
    Breakthrough over 10 years
    @Ramhound one that isn't run under a process scheduler, i.e. one that isn't run under a multitasking operating system. This was possible to do in DOS, but Windows itself schedules when that particular code is run, and for how long (it will interrupt the process, and allow more to continue running until it is your processes' "turn" again).
  • surfasb
    surfasb over 10 years
    I think "real time" is a better word than "bare-metal"
  • Jamie Hanrahan
    Jamie Hanrahan over 9 years
    It's amazing how much OS code is involved to do even simple tasks. The printf of your typical "Hello world" program, if run in a character-mode window in Windows, actually takes more OS code (some of it running in another process!) than would putting up a simple message window. There's a lot of code involved in I/O to anything, for that matter. A program confined to calling NO OS functions might "run" but it could not read any data from anywhere nor send any results anywhere. Might as well not run it.
  • Breakthrough
    Breakthrough over 9 years
    @JamieHanrahan and on some systems (e.g. embedded microcontrollers) the "Hello world" program is something like "flash this LED over and over". Programs run on a variety of processors and systems; infact, the C language has provisions for systems without any input or display. The goal of an OS is to provide unified access to hardware for a wide variety of different programs with different purposes, and/or to allow for easier multitasking. Of course a "Hello world" program on a high-level OS requires more process code, as you do need a way to interact with the display, now...
  • Jamie Hanrahan
    Jamie Hanrahan over 9 years
    Yes, of course. (I hate to tell you this, but my experience goes back to computers that had what were then called "sense switches" and "sense lights". For that matter, anyone who ever owned the original Altair 8800 had a similar "user interface.") But the answer to which I'm commenting here referred to "Windows or Linux", an OS with a scheduler, etc. That's the context in which I was commenting.
  • Mahdi Amrollahi
    Mahdi Amrollahi over 8 years
    indeed, that is the performance for all applications and services except System Idle Process .