Last active
August 29, 2015 14:27
-
-
Save tkuchiki/a6ab436fc1188e01303c to your computer and use it in GitHub Desktop.
cgroups で制限をかけるラッパースクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USER=$(whoami) | |
GROUP=$(id --group --name) | |
sudo cgcreate -t ${USER}:${GROUP} -a ${USER}:${GROUP} -g cpu,memory:/${USER} | |
FREE_MEM=$(free -b | grep 'buffers/cache' | awk '{print $4}') | |
MEM=$(perl -MPOSIX -e "print POSIX::floor(${FREE_MEM} * 0.1);") | |
cgset -r memory.limit_in_bytes="${MEM}" ${USER} | |
cgset -r cpu.cfs_quota_us=50000 ${USER} | |
cgexec -g cpu,memory:${USER} "${@}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yum install -y libcgroup | |
service cgconfig start | |
chkconfig cgconfig on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment