#!/bin/sh 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() { top -w512 -bn1 -o '%MEM' | sed -e '1,/^$/d' | { while read line do set -- $line [ "${12} ${13}" = "Web Content" ] || continue [ "${8}" != Z ] || continue echo $1 done } } main "$@"