In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to achieve the shell script that consumes CPU resources. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The code is as follows:
#! / bin/sh
# filename killcpu.sh
If [$#! = 1]; then
Echo "USAGE: $0"
Exit 1
Fi
For i in `seq $1`
Do
Echo-ne "
ITunes 0
While true
Do
I=i+1
Done "| / bin/sh &
Pid_array [$I] = $!
Done
For i in "${pid_array [@]}"; do
Echo 'kill' $I';'
Done
The method is very simple. Parameter 3 means that 3 CPU resources are consumed. After running, there will be a bunch of kill commands to facilitate the kill process:
The code is 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% us, 0% sy, 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
This is the end of this article on "how to achieve a shell script that consumes CPU resources". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.