Skip to content

Instantly share code, notes, and snippets.

@arsham
Last active January 18, 2017 11:13
Show Gist options
  • Save arsham/95cc37359b6450b0577b9828d2f53599 to your computer and use it in GitHub Desktop.
Save arsham/95cc37359b6450b0577b9828d2f53599 to your computer and use it in GitHub Desktop.
Wroking with cgroups
# Taken from here: https://wiki.archlinux.org/index.php/cgroups
# You need: libcgroup and cgmanager apps.
# Then start the daemon:
sudo systemctl start cgmanager.service
# Creating the group
sudo cgcreate -a arsham:users -t arsham:users -g memory,cpu:GROUP_NAME
# To create subgroups
sudo cgcreate -a arsham:users -t arsham:users -g memory,cpu:GROUP_NAME/SUB_GROUP_NAME
# Limiting memory
echo 100000000 > /sys/fs/cgroup/memory/GROUP_NAME/memory.limit_in_bytes
# Limiting CPU shares
echo 1 > /sys/fs/cgroup/cpu/GROUP_NAME/cpu.shares
# Running an app in the group
cgexec -g cpu,memory:GROUP_NAME APP_NAME
# Deleting the group
sudo cgdelete -g memory,cpu:GROUP_NAME
# If you already have a subgroup be sure to remove the subgroup first
sudo cgdelete -g memory,cpu:GROUP_NAME/SUB_GROUP_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment