diff options
Diffstat (limited to 'ioslay-mgr.sh')
-rwxr-xr-x | ioslay-mgr.sh | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/ioslay-mgr.sh b/ioslay-mgr.sh index d4f545c..d7ce1cb 100755 --- a/ioslay-mgr.sh +++ b/ioslay-mgr.sh | |||
@@ -1,16 +1,16 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/bash |
2 | 2 | ||
3 | ioslay= | 3 | ioslay= |
4 | each_new_process() | 4 | each_new_process() |
5 | { | 5 | { |
6 | while read pid _ | 6 | while read pid _ |
7 | do | 7 | do |
8 | set -- "$@" $pid | 8 | read -N 10001000 procs < /sys/fs/cgroup/$group/cgroup.procs |
9 | set -- $procs | ||
9 | 10 | ||
10 | # filter non-existent processes | 11 | for pid in "$@" |
11 | for _ in "$@" | ||
12 | do | 12 | do |
13 | if [ -e /proc/"$1" ] | 13 | if read comm < /proc/$pid/comm && [ "$comm" = 'Web Content' ] |
14 | then | 14 | then |
15 | set -- "$@" "$1" | 15 | set -- "$@" "$1" |
16 | fi | 16 | fi |
@@ -19,7 +19,11 @@ each_new_process() | |||
19 | 19 | ||
20 | if [ "$ioslay" ] | 20 | if [ "$ioslay" ] |
21 | then | 21 | then |
22 | kill $(pgrep -P $ioslay) | 22 | children=$(pgrep -P $ioslay) |
23 | if [ "$children" ] | ||
24 | then | ||
25 | kill $children | ||
26 | fi | ||
23 | wait $ioslay | 27 | wait $ioslay |
24 | fi | 28 | fi |
25 | 29 | ||
@@ -45,7 +49,41 @@ get_uid() | |||
45 | ) | 49 | ) |
46 | } | 50 | } |
47 | 51 | ||
48 | # group=firefox~$(get_uid) | 52 | #cgroup-show-each-new-process "$group" | grep --line-buffered 'Web Content' | each_new_process |
49 | group=firefox~1000 | 53 | |
54 | # Really, could just check for any/first cgroup with processes and basename | ||
55 | # 'firefox'. Fork for each one. | ||
56 | |||
57 | uid=1000 | ||
58 | group=user.slice/user-$uid.slice/firefox | ||
59 | wantcomm='Web Content' | ||
60 | ioslay= | ||
61 | lastprocs= | ||
62 | while true | ||
63 | do | ||
64 | read -N 1000100 procs < /sys/fs/cgroup/$group/cgroup.procs | ||
65 | if [ "$procs" ] | ||
66 | then | ||
67 | set -- | ||
68 | for pid in $procs | ||
69 | do | ||
70 | read comm < /proc/$pid/comm | ||
71 | if [ "$comm" = "$wantcomm" ] | ||
72 | then | ||
73 | set -- "$@" "$pid" | ||
74 | fi | ||
75 | done | ||
76 | |||
77 | echo "pids: ($*|$(echo $procs))" >&2 | ||
78 | if [ "$lastargs" != "$*" ] | ||
79 | then | ||
80 | [ -z "$ioslay" ] || kill $ioslay $(pgrep -P $ioslay) | ||
81 | wait $ioslay | ||
82 | ioslay-firefox "$@" & | ||
83 | ioslay=$! | ||
84 | fi | ||
85 | lastargs=$* | ||
86 | fi | ||
87 | sleep 1 | ||
88 | done | ||
50 | 89 | ||
51 | cgroup-show-each-new-process "$group" | grep --line-buffered 'Web Content' | each_new_process | ||