1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| #/bin/bash
# LY
# ------------------
# Copyright 2016.04.17 LingYi (lydygly@163.com) QQ:1519952564
cpu_(){
while :; do
echo "This is a test information" >/dev/null
sleep 0.1
done
}
kill_cpu_(){
i=1
for process in $(ps aux | grep $1 | head -n -1 | awk '{print $2}'); do
if [[ ${process} != ${2} ]]; then kill -9 ${process}; let i++; fi
let i++
done
}
echo -e "\033[1;32mInput one number of the processes that will run in background.\033[0m"
echo -e "\033[1;32mWhen they are running, you can use the command \"top\" to monitor in another window.\033[0m"
echo -e "\033[1;32mKill the all processes, just press \"Enter\" key with inputing nothing.\033[0m"
echo -e "\033[1;32m\"Ctrl + c\" or press "Q" to exit.\033[0m"
while :; do
echo -ne "\033[1;34m\nInput number [ 1 - N ]: "
echo -ne "\033[1;31m"
read num_moment
echo -ne "\033[0m"
if [[ ${num_moment} == 'q' ]] || [[ ${num_moment} == 'Q' ]]; then exit 0; fi
if [[ ! -z ${num} ]]; then kill_cpu_ $0 $$ >/dev/null 2>&1; fi
num=${num_moment}
for ((i=1; i<=num; i++)); do
cpu_ &
done
done
|