当前位置:网站首页>Use cpulimit to free up your CPU
Use cpulimit to free up your CPU
2022-06-24 08:33:00 【User 1091747】
stay Linux The recommended tool for managing system resources on the system is cgroups. Although in terms of adjustable restrictions (CPU、 Memory 、 disk I/O、 Network, etc ) Very powerful , But configuration cgroups Not simple .nice Command from the 1973 It can be used since . But it just adjusts the scheduling priority between processes competing for time on a processor .nice The command does not limit what a process can consume per unit time CPU Percentage of period .cpulimit The command provides the best solution for both worlds . It limits the amount of time a process can allocate per unit of time CPU Percentage of period , And relatively easy to call .
cpulimit The command is mainly for long-running and CPU Intensive processes are useful . Compiling software and converting video are common examples of long-running processes , They can make the computer CPU Maximum utilization . Limit the of such processes CPU Utilization will free up processor time , For other tasks that may run on your computer . Limit CPU Intensive processes will also reduce power consumption and heat output , And may reduce the fan noise of the system . Limit the of a process CPU The cost of utilization is , It takes more time to finish running .
install cpulimit
cpulimit The command is in the default Fedora Linux Available in the warehouse . Run the following command , stay Fedora Linux Installation on system cpulimit:
$ sudo dnf install cpulimit
see cpulimit Documents
cpulimit There are no man pages attached to the package . Use the following command to view cpulimit Built in documentation . The output is provided below . But you may need to run this command on your own system , To prevent options from changing since this article was written .
$ cpulimit --helpUsage: cpulimit [OPTIONS…] TARGET OPTIONS -l, --limit=N percentage of cpu allowed from 0 to 800 (required) -v, --verbose show control statistics -z, --lazy exit if there is no target process, or if it dies -i, --include-children limit also the children processes -h, --help display this help and exit TARGET must be exactly one of these: -p, --pid=N pid of the process (implies -z) -e, --exe=FILE name of the executable program file or path name COMMAND [ARGS] run this command and limit it (implies -z)
demonstration
To demonstrate cpulimit How to use the command , Here is a well-designed 、 A lot of calculation Python Script . The script first runs without restrictions , Then limit to 50% Operation in case of . It calculates the number 42 individual Fibonacci number Value . In both cases, the script acts as time The subprocess of the command runs , To display the total time required to calculate the answer .
$ /bin/time -f '(computed in %e seconds)' /bin/python -c 'f = lambda n: n if n<2 else f(n-1)+f(n-2); print(f(42), end=" ")'267914296 (computed in 51.80 seconds)$ /bin/cpulimit -i -l 50 /bin/time -f '(computed in %e seconds)' /bin/python -c 'f = lambda n: n if n<2 else f(n-1)+f(n-2); print(f(42), end=" ")'267914296 (computed in 127.38 seconds)
When running the first version of the command , You may hear on the computer CPU The fan turns . But when running the second version , You should not . The first version of the command is not affected by CPU The limitation of , But it should not paralyze your computer . It is written in such a way : It can only use at most one CPU The core . Most modern PC There are many CPU The core , When one of them CPU 100% When busy , You can run other tasks at the same time without difficulty . To verify that the first command maximizes one of your processors , Run in a separate terminal window top Command and press 1 key . To exit top You can press the command Q key .
Set higher than 100% The limit is only to be able to Task parallelization Your program makes sense . For such a program , higher than 100% The increment of represents a CPU Total utilization of (200%=2 individual CPU,300%=3 individual CPU, wait ).
Be careful , In the example above ,-i Options have been passed to cpulimit command . This is necessary , Because the command to limit is not cpulimit Direct subprocess of the command . contrary , It is time A subprocess of the command , The latter is cpulimit A subprocess of the command . without -i Options ,cpulimit Will only limit time command .
The last show
If you want to limit a graphics program that starts from a desktop icon , Please send... Of the program .desktop file ( Usually located in /usr/share/applications Under the table of contents ) Copy to your ~/.local/share/applications Under the table of contents , And modify it accordingly Exec That's ok . Then run the following command to apply these changes :
$ update-desktop-database ~/.local/share/applications
边栏推荐
- List of Li Bai's 20 most classic poems
- Which is the first poem of Tang Dynasty?
- Nodejs redlock notes
- 【微服务~Nacos】Nacos服务提供者和服务消费者
- 貸款五級分類
- [untitled]
- 常用日期格式符与Qt获取当前时间的办法
- 新准则金融资产三分类:AMC、FVOCI和FVTPL
- 一文带你了解Windows操作系统安全,保护自己的电脑不受侵害
- How to improve the customer retention rate in the operation of independent stations? Customer segmentation is very important!
猜你喜欢

根据网络上的视频的m3u8文件通过ffmpeg进行合成视频

C language_ Love and hate between string and pointer

Swift extension chainlayout (UI chain layout) (source code)

Maya re deployment

Longhorn installation and use

ZUCC_编译语言原理与编译_实验04 语言与文法

ZUCC_编译语言原理与编译_实验05 正则表达式、有限自动机、词法分析

LabVIEW查找n个元素数组中的质数

Qt导出PDF文件的两种方法

ZUCC_ Principles of compiling language and compilation_ Experiment 05 regular expression, finite automata, lexical analysis
随机推荐
OpenCV get(propId) 常用的值
The article takes you to understand the security of Windows operating system and protect your computer from infringement
一文带你了解Windows操作系统安全,保护自己的电脑不受侵害
11--无重复字符的最长子串
Question 4 - datepicker date selector, disabling two date selectors (start and end dates)
Scénarios d'utilisation de la promesse
OpenCV to realize the basic transformation of image
jwt(json web token)
Qopengl display point cloud file
Paper notes: multi label learning dm2l
Three categories of financial assets under the new standards: AMC, fvoci and FVTPL
ZUCC_编译语言原理与编译_实验01 语言分析与简介
QPS, TPS, concurrent users, throughput relationship
Review SGI STL secondary space configurator (internal storage pool) | notes for personal use
独立站运营中如何提升客户留存率?客户细分很重要!
os. path. Pits encountered during the use of join()
根据网络上的视频的m3u8文件通过ffmpeg进行合成视频
ZUCC_编译语言原理与编译_实验04 语言与文法
RCNN、Fast-RCNN、Faster-RCNN介绍
Tool functions – get all files in the project folder