Killall Automation and then Killall Level 9

Sometimes I want a killallspecific process, but the launch killalldoes not work. Therefore, when I try to start the process again, it fails because the previous session is still running. Then I will have to tediously run killall -9on it. Therefore, to simplify my life, I created a realkillscript and it looks like this:

PIDS=$(ps aux | grep -i "$@" | awk '{ print $2 }') # Get matching pid's.
kill $PIDS 2> /dev/null # Try to kill all pid's.
sleep 3
kill -9 $PIDS 2> /dev/null # Force quit any remaining pid's.

So, is this the best way to do this? How can I improve this script?

+3
source share
3 answers

killall, , UNIX . "Proctools" pkill pgrep :

for procname; do
    pkill "$procname"
done

sleep 3
for procname; do
    # Why check if the process exists if you're just going to `SIGKILL` it?
    pkill -9 "$procname"
done

(Edit) , , , PID:

pids=()
for procname; do
    pids+=($(pgrep "$procname"))
done
# then proceed with `kill`

, SIGKILL, . . SIGTERM, , , -. , ( ? ?) , .

+5

, , , , , , , , , /. kill -9 , , .

, , , kill -9 . , , , , ? INT TERM .

+2

This is unlikely, but it is possible that during this 3-second wait, a new process could take over this PID, and the second would kill it.

+2
source

All Articles