当前位置:网站首页>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
边栏推荐
- [xinliu-s6 new model +sa 3-star Xinghai] the new two-way server of the third generation chip was launched and the product was updated~
- Export MySQL database to xxx SQL, set xxx The SQL file is imported into MySQL on the server. Project deployment.
- ZUCC_编译语言原理与编译_实验02 FSharp OCaml语言
- Search and recommend those things
- 487. number of maximum consecutive 1 II ●●
- Micro build low code online "quick registration applet" capability
- 基金的募集,交易与登记
- Five level classification of loans
- 【毕业季】你好陌生人,这是一封粉色信笺
- List of Li Bai's 20 most classic poems
猜你喜欢

Two methods of QT exporting PDF files

About the iframe anchor, the anchor is offset up and down, and the anchor has page display problems Srcdoc problem of iframe

Use of swift basic closure /block (source code)

小样本故障诊断 - 注意力机制代码 - BiGRU代码解析实现

1279_ Vsock installation failure resolution when VMware player installs VMware Tools

A preliminary study of IO model

RCNN、Fast-RCNN、Faster-RCNN介绍

PAT 1157:校庆

List of Li Bai's 20 most classic poems

For a detailed explanation of flex:1, flex:1
随机推荐
Qmenu response in pyqt
11--无重复字符的最长子串
OpenCV to realize the basic transformation of image
JUC personal simple notes
List of Li Bai's 20 most classic poems
WCF TCP protocol transmission
2021-06-24: find the length of the longest non repeating character substring in a string.
一文带你了解Windows操作系统安全,保护自己的电脑不受侵害
Industrial computer anti cracking
js滚动div滚动条到底部
Synthesize video through ffmpeg according to m3u8 file of video on the network
How to improve the customer retention rate in the operation of independent stations? Customer segmentation is very important!
2021-03-16 comp9021 class 9 notes
MAYA重新拓布
WPS的JS宏实现图片正文在同一段落的分离方法
[introduction to point cloud dataset]
2021-06-25: a batch of strings consisting only of lowercase letters (a~z) are put
Robot acceleration level task priority inverse kinematics
Live broadcast review | detailed explanation of koordinator architecture of cloud native hybrid system (complete ppt attached)
Five level classification of loans