-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpstop.sh
More file actions
executable file
·81 lines (69 loc) · 1.44 KB
/
pstop.sh
File metadata and controls
executable file
·81 lines (69 loc) · 1.44 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#/bin/bash -
#第2个参数如果是数字则为行号...
#第2个参数如果是非数字则是关键字,且第3个参数如果存在,会覆盖第2个参数。
#how boring.It should be thrown to trash...
#2013-04-02 星期二 18:59
LANG=C
if [ a"$1" == a"-h" ]
then
echo "$0 [option] [lineNumber] [keyword]"
exit 0
fi
$(echo "$2"|grep -q '^[0-9]\+$') && lines=$2 || keyword=$2
if [ ! "${lines}" ] || [ "${lines}" -le "0" ]
then
lines=10
fi
#占cpu最高的前10个进程
if [ "$1" == "-cpu" ]
then
cmd="ps auxw | head -1;ps auxw | grep -v PID | sort -rnk3 | head -n ${lines}"
if [ "$3" ]
then
keyword=$3
fi
if [ "${keyword}" ]
then
cmd=$(echo ${cmd} | sed "s;$; | grep ${keyword};")
fi
echo "${cmd}" | bash
exit 0
fi
#占memory最高的前10个进程
if [ "$1" == "-mem" ]
then
cmd="ps auxw | head -1;ps auxw | grep -v PID | sort -rnk4 | head -n ${lines}"
if [ "$3" ]
then
keyword=$3
fi
if [ "${keyword}" ]
then
cmd=$(echo ${cmd} | sed "s;$; | grep ${keyword};")
fi
echo "${cmd}" | bash
exit 0
fi
#ps出的vsz总数
if [ "$1" == "-vsz" ]
then
echo "VSZ_total"
ps aux | tail -n +2 | awk '{print $5}' | tr '\n' '+' | sed 's;$;0\n;g'|bc
exit 0
fi
#ps出的RSS总数
if [ "$1" == "-rss" ]
then
echo "RSS_total"
ps aux | tail -n +2 | awk '{print $6}' | tr '\n' '+' | sed 's;$;0\n;g'|bc
exit 0
fi
#查找关键字
if [ "$1" ]
then
ps auxw | head -1;
ps auxw | grep -- $1
exit 0
fi
#无关键字则输出所有进程
ps auxw