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