Bash – How to Kill All Active Processes

bash

I could close specified apps like

$ killall "PDF Expert"
$ killall "Google Chrome"

The active processes could be check with command top

enter image description here

How could I kill all the process with codes like

for process in processes; do
       killall "$process"

Best Answer

There is a much more powerful command on the shell to kill processes. Have a look at the "pkill" command syntax:

    PKILL(1)                  BSD General Commands Manual                 PKILL(1)

NAME
     pgrep, pkill -- find or signal processes by name

SYNOPSIS
     pgrep [-Lafilnoqvx] [-F pidfile] [-G gid] [-P ppid] [-U uid] [-d delim] [-g pgrp] [-t tty]
           [-u euid] pattern ...
     pkill [-signal] [-ILafilnovx] [-F pidfile] [-G gid] [-P ppid] [-U uid] [-g pgrp] [-t tty] [-u euid]
           pattern ...

My personal favourite for killing specific processes is

pkill -9 -u <user> -f <Match against full argument lists.>

So if I want to kill all processes from the Razer Synapse software, because the update agent sometimes has hung up and the Razer Synapse Tool does not start, I type

Tatooine-2257:~ mallert$ ps -eaf | grep Razer
  503 87700     1   0 12:46pm ??        15:46.40 /Library/Application Support/Razer/RzUpdater.app/Contents/MacOS/RzUpdater
  503 87749     1   0 12:46pm ??        30:42.02 /Library/Application Support/Razer/RzDeviceEngine.app/Contents/MacOS/RzDeviceEngine
  503 92697     1   0  2:04pm ??         0:13.17 /Applications/Razer Synapse.app/Contents/MacOS/Razer Synapse
  503 42720  1007   0 10:02pm ttys006    0:00.00 grep Razer
Tatooine-2257:~ mallert$ pkill -9 -f Razer