From 4e93a2d8b757b554acbe5c791d3effe0abd43716 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Fri, 22 Oct 2021 09:38:29 -0400 Subject: automatic restarting of "iotop" to pick up new firefox pids --- fireslay | 89 +++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 26 deletions(-) (limited to 'fireslay') diff --git a/fireslay b/fireslay index 0b26c86..1926e19 100755 --- a/fireslay +++ b/fireslay @@ -1,10 +1,67 @@ #!/bin/sh -if [ "$1" = -q ] -then - exec 2>/dev/null - shift -fi +die() +{ + printf '%s: Error: %s\n' "$0" "$*" >&2 + exit 1 +} + +parseopts() +{ + while [ $# -gt 0 ] + do + case "$1" in + -q | --quiet ) + exec 2>/dev/null + ;; + -y | --kill-last-process ) + FIRESLAY_KILL_LAST_PROCESS=y + ;; + --) + shift + break + ;; + -* ) + die unknown option + ;; + *) + break + ;; + esac + shift + done + [ $# = 0 ] || die usage +} + +main() +{ + parseopts "$@" + + set -- $(web_content_pids) + + ( + case $# in + 0 ) echo "$0: Warning: Not slaying: no Web Content process found." >&2 + exit + ;; + 1 ) if ! [ "$FIRESLAY_KILL_LAST_PROCESS" ] + then + echo "$0: Warning: Not slaying: only one 'Web Content' process. Specify -y to kill it." >&2 + exit + fi + ;; + * ) shift + ;; + esac + set -x + ps $* >&2 + kill $* + ) + + r=$? + ps $* >&2 + exit $r +} web_content_pids() { @@ -18,25 +75,5 @@ web_content_pids() } } -set -- $(web_content_pids | tac) +main "$@" -case $# in - 0) - echo "$0: Warning: Not slaying: no Web Content process found." >&2 - exit - ;; - 1) - echo "$0: Warning: Not slaying: only one Web Content process found." >&2 - ps $* >&2 - exit - ;; -esac - -( - set -x - ps $1 >&2 - kill $1 -) -r=$? -ps $* >&2 -exit $r -- cgit v1.2.3