Linux kill processes with CPUs greater than 50% every 1 seconds

Source: Internet
Author: User

1. Create a new/test/killcpu.sh shell script and grant permissions 0755
#!/bin/bash
PS axf-o "pid%cpu" | awk ' {if ($2>=50.0) print $} ' | While Read procid
Do
Kill-9 $procid
Done

2. Installing crontab
Yum-y Install Vixie-cron
3. View Scheduled Tasks Crontab-l
4. Add a timed task Crontab-e

Time- sharing weekly command
The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
6th List of commands to run
# for Excuting killcpu.sh every 3 seconds# #on 2017-03-09 Execute script every 3 seconds
*/1 * * * */test/killcpu.sh
*/1 * * * * * sleep 3 &&/test/killcpu.sh
*/1 * * * * * sleep 6 &&/test/killcpu.sh
*/1 * * * * * sleep 9 &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep Wuyi &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
#-----------------------------------------------------------------

# for Excuting killcpu.sh every 1 seconds# #on 2017-03-09 Execute script every 1 seconds
*/1 * * * */test/killcpu.sh
*/1 * * * * * sleep 1 &&/test/killcpu.sh
*/1 * * * * * sleep 2 &&/test/killcpu.sh
*/1 * * * * * sleep 3 &&/test/killcpu.sh
*/1 * * * * * sleep 4 &&/test/killcpu.sh
*/1 * * * * * sleep 5 &&/test/killcpu.sh
*/1 * * * * * sleep 6 &&/test/killcpu.sh
*/1 * * * * * sleep 7 &&/test/killcpu.sh
*/1 * * * * * sleep 8 &&/test/killcpu.sh
*/1 * * * * * sleep 9 &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep Panax &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep Wuyi &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
*/1 * * * * * sleep &&/test/killcpu.sh
#-----------------------------------------------------------------
5. Restart Service Crond Restart
6. Add boot chkconfig--list crond
7. Check the boot start service chkconfig

Linux kill processes with CPUs greater than 50% every 1 seconds

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.