Home·Terminal commands

pkill

Processes and system

Usage

pkill [-SIGNAL] [-f] <pattern>

Kills every process matching a pattern; without `-f` only the process name is compared, and a loose pattern takes down more than you meant, so run pgrep with the same pattern first.

Common flags

FlagMeaning
-fMatch against the whole command line, not just the process name.
-u <user>Restrict to one user.
-xRequire the whole name to match, not a substring.
-n / -oOnly the newest / only the oldest matching process.
-9Force instead of asking the process to exit.
-iCase-insensitive matching.

Examples

pgrep -af "node server.js" && pkill -f "node server.js"

Look first, then kill exactly what you saw.

pkill -u deploy -f gunicorn

Stop the deploy user's gunicorn workers.

What is running and what is eating the machine. Identifying it comes before killing it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does pkill do?

Kills every process matching a pattern; without `-f` only the process name is compared, and a loose pattern takes down more than you meant, so run pgrep with the same pattern first.

Q. How do I type it?

pkill [-SIGNAL] [-f] <pattern> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man pkill. This command sits under Processes and system.

Related commands

man page: man pkill