Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Last active August 29, 2015 14:27
Show Gist options
  • Save tkuchiki/a6ab436fc1188e01303c to your computer and use it in GitHub Desktop.
Save tkuchiki/a6ab436fc1188e01303c to your computer and use it in GitHub Desktop.
cgroups で制限をかけるラッパースクリプト
#!/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} "${@}"
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