Skip to content

Instantly share code, notes, and snippets.

@paoloantinori
Last active May 30, 2019 11:58
Show Gist options
  • Save paoloantinori/3e1ed14f75c1e3e332bce8b11b34706c to your computer and use it in GitHub Desktop.
Save paoloantinori/3e1ed14f75c1e3e332bce8b11b34706c to your computer and use it in GitHub Desktop.
How to spawn a bash shell with limited memory limits .
sudo dnf install libcgroup-tools
export MY_CGROUP_NAME="java_build"
export MY_SUBSYSTEMS="memory"
# create cgroup according to above vars
sudo cgcreate -t $USER:$USER -a $USER:$USER -g $MY_SUBSYSTEMS:$MY_CGROUP_NAME
# lazily use this to calculate bytes: http://extraconversion.com/data-storage/gibibytes/gibibytes-to-bytes.html
MEMORY_VALUE_IN_BYTES=$(python -c 'print int(0.3 * 1024 * 1024 * 1024) ') # first number is the number of GiB
# configure cgroup limits
sudo cgset -r memory.limit_in_bytes=$MEMORY_VALUE_IN_BYTES $MY_CGROUP_NAME
# verify group exists
# ls -al /sys/fs/cgroup/$MY_SUBSYSTEMS/$MY_CGROUP_NAME/
cgexec -g $MY_SUBSYSTEMS:$MY_CGROUP_NAME /bin/bash
# verify shell belongs to the right cgroup
ps -o cgroup $BASHPID
./tools/bin/syndesis build --batch-mode --module ui-angular,ui-react --docker | tee build_log.txt
ps -o cgroup $BASHPID
# if you want to delete the group (ignore the error)
# cgdelete -g $MY_SUBSYSTEMS:$MY_CGROUP_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment