Shell script that consumes CPU resources

Source: Internet
Author: User
Shell scripts that consume CPU resources in an endless loop. if the server has multiple CPUs, you can select the number of CPU resources to consume :#! /Bin/sh # filenamekillcpu. shif [$ #! 1]; thenecho & quot; USAGE: $0 & lt; CPUs & gt; & quot; exit1... shell scripts that consume CPU resources in an endless loop. if the server has multiple CPUs, you can select the number of CPU resources to consume :#! /Bin/sh # filename killcpu. shif [$ #! = 1]; then echo "USAGE: $0 "Exit 1; when or I in 'seq $1 'do echo-ne" I = 0; while truedoi = I + 1; done "|/bin/sh & pid_array [$ I] = $!; Done for I in "$ {pid_array [@]}"; do echo 'Kill '$ I'; '; the usage of done is very simple, parameter 3 indicates that three CPU resources are consumed. after running, there will be a bunch of kill commands to facilitate the kill process: [root @ test02 ~] #./Killcpu. sh 3 kill 30104; kill 30106; kill 30108; [root @ test02 ~] # Top-15:27:31 up 264 days, 4 users, load average: 0.86, 0.25, 0.19 Tasks: 185 total, 5 running, 180 sleeping, 0 stopped, 0 zombieCpu0: 100.0% us, 0.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% siCpu1: 0.0% us, 0.0% sy, 0.0% ni, 100.0% id, 0.0% wa, 0.0% hi, 0.0% siCpu2: 100.0% us, 0.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% siCpu3: 100.0% us, 0.0% sy, 0.0% ni, 0.0% id, 0.0% wa, 0.0% hi, 0.0% siMem: 8165004 k total, 8095880 k used, 69124 k free, 53672 k buffersSwap: 2031608 k total, 103548 k used, 1928060 k free, 6801364 k cached
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.