blob: fdb5396dffb2dbfb57e1d817302e49ea6b7fa4f2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#!/usr/bin/env sh
# Description: Fuzzy list and kill a (zombie) process by name
#
# Requires: fzf or fzy, ps
#
# Note: To kill a zombie process enter "zombie"
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana
printf "Enter process name ['defunct' for zombies]: "
read -r psname
# shellcheck disable=SC2009
if ! [ -z "$psname" ]; then
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
elif which fzy >/dev/null 2>&1; then
fuzzy=fzy
else
exit 1
fi
cmd="$(ps -ax | grep -iw "$psname" | "$fuzzy" | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
$sucmd kill -9 "$cmd"
fi
|