Sobes.tech
Middle

Kuidas hallata CPU prioriteeti Linuxis (CPU piiramine)?

sobes.tech AI

Vastus AI-lt

In Linux, CPU priority management for processes is done via:

  • nice/renice: changes the scheduling priority of the process. Nice values range from -20 (high priority) to 19 (low priority).

    # Start a process with nice priority 10
    nice -n 10 ./my_process
    
    # Change the priority of an already running process
    renice 5 -p <pid>
    
  • cgroups (control groups): allow limiting the use of CPU, memory, and other resources for groups of processes.

  • cpulimit: utility to limit the CPU usage of a specific process in percentage.

    cpulimit -p <pid> -l 30  # limit process to 30% CPU
    

Thus, for CPU throttling, nice can be used for priority, and cgroups or cpulimit for strict consumption limits.