-
Notifications
You must be signed in to change notification settings - Fork 1
/
opscg
executable file
·160 lines (148 loc) · 2.58 KB
/
opscg
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
#write by shuaili
while getopts ":b:m:p:irdlchv" optname
do
case "$optname" in
"b")
basefile=$OPTARG
;;
"m")
groupname=$OPTARG
;;
"d")
rmpid=true
;;
"r")
rm_cg=true
;;
"p")
procpid=$OPTARG
;;
"l")
list_cg=true
;;
"c")
create_cg=true
;;
"h")
echo "help:$0 "
;;
"v")
debuglabel=true
;;
"?")
echo "Unknown option $OPTARG"
;;
":")
echo "No argument value for option $OPTARG"
;;
*)
echo "Unknown error while processing options"
;;
esac
done
[[ $basefile ]] && base=$(cat basefile)
[[ $basefile ]] || base="
cpu.shares=128
memory.limit_in_bytes=10000000000
blkio.weight=100
"
for i in $base
do
pra=${i%%=*}
value=${i#*=}
maxv=$(cgget -r $pra / | grep -v "/:" |awk '{print $NF}')
let ts=$maxv/$value
[[ $maxts ]] || maxts=$ts
[[ $ts -lt $maxts ]] && maxts=$ts
done
[[ $debuglabel ]] && echo maxts is $maxts
if [[ $create_cg ]]
then
i=1
while [[ $i -le $maxts ]]
do
gn=${i}_times
for j in $base
do
pra=${j%%=*}
cg=${pra%%.*}
let value=${j#*=}*$i
cgcreate -g $cg:$gn
cgset -r $pra=$value /$gn
done
let i=i*2
done
fi
if [[ $list_cg ]]
then
echo -e -n "root_cg\t\t"
for j in $base
do
pra=${j%%=*}
cg=${pra%%.*}
dis=$(cgget -r $pra / 2>/dev/null|grep -v "/"|sed -e "s/ //")
echo -e -n "$dis\t\t"
done
echo
i=1
while [[ $i -le $maxts ]]
do
gn=${i}_times
echo -e -n "$gn\t\t"
for j in $base
do
pra=${j%%=*}
cg=${pra%%.*}
value=${j#*=}
dis=$(cgget -r $pra /$gn 2>/dev/null|grep -v "$gn"|sed -e "s/ //")
echo -e -n "$dis\t\t"
done
echo
if [[ $debuglabel ]]
then
grep "$gn" /proc/*/cgroup |awk -F '/' '{print $3}'|sort |uniq
fi
let i=i*2
done
fi
if [[ $rm_cg ]]
then
i=1
while [[ $i -le $maxts ]]
do
gn=${i}_times
for j in $base
do
pra=${j%%=*}
cg=${pra%%.*}
value=${j#*=}
cgdelete -r $cg:$gn
done
echo
let i=i*2
done
fi
if [[ $procpid ]]
then
pidlist=`ps -eLf |awk -v pid=$procpid '{if($2==pid){print $4}}'`
fi
if [[ $groupname ]]
then
for i in $base
do
pra=${i%%=*}
cg=${pra%%.*}
value=${i#*=}
cgclassify -g $cg:$groupname --sticky $procpid $pidlist
done
fi
if [[ $rmpid ]]
then
for i in $base
do
pra=${i%%=*}
cg=${pra%%.*}
cgclassify -g $cg:/ --sticky $procpid $pidlist
done
fi