-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathram-limiter
28 lines (20 loc) · 1.02 KB
/
ram-limiter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
if cat /etc/cgconfig.conf | grep "group limited {"
then
echo "Group already there"
else
sudo echo "group limited {
memory {
memory.limit_in_bytes = 400M;
}
}" | sudo tee -a /etc/cgconfig.conf #This adds the group limited to cgroup. If you want different memory limits, either change 400M before first run, or run sudo $EDITOR /etc/cgconfig.conf and edit the file to read whatever you need.
fi
sudo systemctl restart cgconfig
sudo chown -R $USER /sys/fs/cgroup/memory/limited #Allows your user to run apps with the cgroup settings.
program=$(zenity --entry --title="cGroup Memory Limiter" --text "What is the name of the program you want to run limited?" --entry-text firefox) #Grab the program name.
if which $program
then
cgexec -g memory:limited $(which $program) #The command to run said program with the limited memory.
else
zenity --error --text="Can not find that program, please check your speeling"
fi