Shell scripts that consume CPU resources _linux shell

Source: Internet
Author: User

Copy Code code as follows:

#! /bin/sh
# filename killcpu.sh
If [$#!= 1]; Then
echo "USAGE: $ <CPUs>"
Exit 1;
Fi
For i in ' seq $ '
Todo
Echo-ne "
i=0;
While True
Todo
i=i+1;
Done "| /bin/sh &
pid_array[$i]=$!;
Done

For i in "${pid_array[@]}"; Todo
echo ' Kill ' $i ';
Done

Using the method is very simple, parameter 3 means consuming 3 CPU resources, after running, there will be a bunch of kill command to facilitate the kill process:

Copy Code code as follows:

[root@test02 ~]#./killcpu.sh 3
Kill 30104;
Kill 30106;
Kill 30108;
[root@test02 ~]# Top
Top-15:27:31 up 264 days, 23:39, 4 users, load average:0.86, 0.25, 0.19
tasks:185 Total, 5 running, 180 sleeping, 0 stopped, 0 zombie
cpu0:100.0% us, 0.0% sy, 0.0% ni, 0.0% ID, 0.0% wa, 0.0% Hi, 0.0% si
cpu1:0.0% us, 0.0% sy, 0.0% ni, 100.0% ID, 0.0% wa, 0.0% Hi, 0.0% si
cpu2:100.0% us, 0.0% sy, 0.0% ni, 0.0% ID, 0.0% wa, 0.0% Hi, 0.0% si
cpu3:100.0% us, 0.0% sy, 0.0% ni, 0.0% ID, 0.0% wa, 0.0% Hi, 0.0% si
mem:8165004k Total, 8095880k used, 69124k free, 53672k buffers
swap:2031608k Total, 103548k used, 1928060k free, 6801364k 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.