It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In RegisterIt looks like you're new here. If you want to get involved, click one of these buttons!
Howdy, Stranger!
It looks like you've been lurking for a while.
If you register, we also will remember what you have read and notify you about new comments. You will also be able to participate in discussions.
So if you'd like to get involved, register for an account, it'll only take you a minute!
sudo apt-get install cpulimit1.2 Installation if using CentOS/Fedora:
sudo yum install epel-releaseAfterward, the installation can be initiated:
sudo yum install cpulimit
orsudo dnf install cpulimit
2. Usage of CPULimit:sudo nano usecpu.shEnter the following code into the usecpu.sh file:
#!/bin/bash while :; do :; done;Save the code on your file. This code will create a loop that will consume all of the server's CPU. When the file is created, set executable permission for it:
sudo chmod +x usecpu.shThe created process can be started using:
./usecpu.sh &After initiation, you will receive a result of process id, for example, 1887:
[1] 1887If everything is correct, the new process should use all of the server's CPU. You can check the usage of your CPU by using the top command:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMANDAs you can see from the table, the usecpu.sh process uses 99.9% of server CPU. Such CPU usage will prevent other processes from working successfully and can finally result in server OS inactivity. This is where CPULimit comes to usage.
2912 root 20 0 12512 896 792 R 99.9 0.0 0:18.38 usecpu.sh
2893 root 20 0 39688 3660 3092 R 0.3 0.2 0:00.02 top
1 root 20 0 37912 6000 4004 S 0.0 0.3 0:01.52 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.05 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
6 root 20 0 0 0 0 S 0.0 0.0 0:00.10 kworker/u2:0
7 root 20 0 0 0 0 S 0.0 0.0 0:00.49 rcu_sched
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
10 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/0
11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
12 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
13 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 perf
14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khungtaskd
15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback
16 root 25 5 0 0 0 S 0.0 0.0 0:00.00 ksmd
cpulimit -l 30 -p 2912 &
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMANDNow the usecpu.sh process CPU consumption will be limited to 31.6% of CPU (can be +/- 5% deflection).
2912 root 20 0 12512 996 896 T 31.6 0.0 0:29.76 usecpu.sh
2915 root 9 -11 8612 1544 1428 S 0.3 0.1 0:00.02 cpulimit
1 root 20 0 37912 6000 4004 S 0.0 0.3 0:01.53 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.06 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
6 root 20 0 0 0 0 S 0.0 0.0 0:00.11 kworker/u2:0
7 root 20 0 0 0 0 S 0.0 0.0 0:00.52 rcu_sched
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
10 root rt 0 0 0 0 S 0.0 0.0 0:00.02 watchdog/0
11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
12 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
13 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 perf
14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khungtaskd
15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback
16 root 25 5 0 0 0 S 0.0 0.0 0:00.00 ksmd
cpulimit -l 25 ./usecpu.sh &