2019-11-01 16:24:31 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
# Description: Fuzzy list and kill a (zombie) process by name
|
|
|
|
#
|
2020-05-06 13:11:01 +00:00
|
|
|
# Dependencies: fzf, ps
|
2019-12-09 13:06:48 +00:00
|
|
|
#
|
2019-11-01 16:24:31 +00:00
|
|
|
# Note: To kill a zombie process enter "zombie"
|
|
|
|
#
|
|
|
|
# Shell: POSIX compliant
|
|
|
|
# Author: Arun Prakash Jana
|
|
|
|
|
2019-11-21 20:44:25 +00:00
|
|
|
printf "Enter process name ['defunct' for zombies]: "
|
|
|
|
read -r psname
|
2019-11-01 16:24:31 +00:00
|
|
|
|
2019-12-09 13:06:48 +00:00
|
|
|
# shellcheck disable=SC2009
|
2019-11-01 16:24:31 +00:00
|
|
|
if ! [ -z "$psname" ]; then
|
2019-12-09 13:06:48 +00:00
|
|
|
if which sudo >/dev/null 2>&1; then
|
|
|
|
sucmd=sudo
|
|
|
|
elif which doas >/dev/null 2>&1; then
|
|
|
|
sucmd=doas
|
|
|
|
else
|
|
|
|
sucmd=: # noop
|
|
|
|
fi
|
|
|
|
|
|
|
|
if which fzf >/dev/null 2>&1; then
|
|
|
|
fuzzy=fzf
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cmd="$(ps -ax | grep -iw "$psname" | "$fuzzy" | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
|
2020-08-20 09:21:26 +00:00
|
|
|
if [ -n "$cmd" ]; then
|
|
|
|
$sucmd kill -9 "$cmd"
|
|
|
|
fi
|
2019-11-01 16:24:31 +00:00
|
|
|
fi
|