Skip to content

Instantly share code, notes, and snippets.

@cwshu
Last active March 6, 2018 19:30
Show Gist options
  • Save cwshu/6983d7b228a6abbd1526f497e6cf2fc0 to your computer and use it in GitHub Desktop.
Save cwshu/6983d7b228a6abbd1526f497e6cf2fc0 to your computer and use it in GitHub Desktop.
#!/bin/sh
# requirement:
# install libcgroup
#
# usage:
# $ ./tc_cgroup.sh
# $ cgexec -g net_cls:gdrive fish
USER=susu
CGROUP_NAME=gdrive
IFACE=eno1
RATE=20mbit
sudo cgcreate -t $USER -a $USER -g net_cls:$CGROUP_NAME
echo 0x100001 > /sys/fs/cgroup/net_cls/$CGROUP_NAME/net_cls.classid
sudo tc qdisc add dev $IFACE root handle 10: htb
sudo tc class add dev $IFACE parent 10: classid 10:1 htb rate $RATE
sudo tc filter add dev $IFACE parent 10: protocol ip prio 10 handle 1: cgroup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment