summaryrefslogtreecommitdiff
path: root/dot/local
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2017-12-11 10:56:29 -0500
committerAndrew Cady <d@jerkface.net>2017-12-11 10:56:54 -0500
commit39d76a825a5f7962a5223730e199497b51294d58 (patch)
tree7cde8e929041900bcd5fb144edc1907782f6fde1 /dot/local
parentcacd19eac9353f070a130040e8ff96f66637e3d9 (diff)
new command: sliceweasel
sliceweasel starts iceweasel with max 50% system memory available to it it requires sudo
Diffstat (limited to 'dot/local')
-rw-r--r--dot/local/bin/sliceweasel26
1 files changed, 26 insertions, 0 deletions
diff --git a/dot/local/bin/sliceweasel b/dot/local/bin/sliceweasel
new file mode 100644
index 0000000..944f12a
--- /dev/null
+++ b/dot/local/bin/sliceweasel
@@ -0,0 +1,26 @@
1#!/bin/bash
2
3command=iceweasel
4memory_ratio=0.5
5control_group=$command
6
7as_root=sudo
8
9total_memory() { free -b | (read line; read Mem total _; echo $total); }
10mkdir_idem() { [ -d "$1" ] || $as_root mkdir "$1"; }
11out() { $as_root tee "$@" >/dev/null; }
12
13total_memory=$(total_memory) || exit 1
14memory_limit_in_bytes=$(bc -q <<< "$total_memory * $memory_ratio / 1" )
15control_group_dir=/sys/fs/cgroup/memory/"$control_group"
16
17mkdir_idem "$control_group_dir"
18out "$control_group_dir"/memory.limit_in_bytes <<< $memory_limit_in_bytes
19
20# This method works (tested).
21# username=$(id -u)
22# exec sudo -E -- cgexec -g memory:"$control_group" -- su "$username" -c "exec $command"
23
24# This method is untested. Should work the same.
25out "$control_group_dir"/cgroup.procs <<< $$
26exec $command