[root@10 cpu]# yum install -y libcgroup-tools.x86_64 libcgroup
#建立分組 [root@localhost ~]# cgcreate -g cpu,cpuset,memory:my1 #設置限制使用cpu 0 [root@localhost ~]# cgset -r cpuset.cpus=0 my1 #設置限制使用的內存條 [root@localhost ~]# cgset -r cpuset.cpus=0 my1 #設置限制cpu最多用到50% [root@localhost ~]# cgset -r cpu.cfs_period_us=100000 my1 [root@localhost ~]# cgset -r cpu.cfs_quota_us=50000 my1 #設置限制內存最大使用大小,這裏單位是byte,這裏限制最多用512M [root@localhost ~]# cgset -r memory.limit_in_bytes=524288000 my1
[root@localhost small]# wget -O mathomatic-16.0.1.tar.bz2 http://download.chinaunix.net/down.php?id=42725&ResourceID=6566&site=1 [root@localhost small]# yum install -y bzip2 [root@localhost small]# bzip2 -b mathomatic-16.0.1.tar.bz2 && tar -xf mathomatic-16.0.1.tar [root@localhost small]# cd mathomatic-16.0.1/primes/ [root@localhost small]# make && make install
[root@localhost ~]# cgexec -g cpuset,memory,cpu:/my1 /usr/local/bin/matho-primes 0 999999999 > /dev/null & [root@localhost ~]# top top - 13:40:49 up 1 day, 2:05, 2 users, load average: 0.00, 0.01, 0.10 Tasks: 180 total, 2 running, 178 sleeping, 0 stopped, 0 zombie %Cpu0 : 50.2 us, 0.0 sy, 0.0 ni, 49.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu1 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu2 : 0.3 us, 0.0 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu3 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 8010804 total, 2646744 free, 4564848 used, 799212 buff/cache KiB Swap: 1679356 total, 1679356 free, 0 used. 3059412 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 6965 root 20 0 9200 2524 488 R 49.8 0.0 0:05.44 matho-primes