sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

pskill (741B)


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