5 Answers
5

Note: Be sure to read the manual page for whichever command you choose to use, in order to see the various options available to the command, as may be relevant to its particular usage. In Terminaltype e.g. man pkill and pressenter, or just type the command and right-click on it, then select: Open man Page

This is the best method, because it replicates what happens when you use File>Quit from the menu.
– BarmarMar 28 at 16:15

2

Huh. I've always used osascript -e 'tell application "Slack" to quit' but if the shorter syntax works, then that's obviously preferable. This is definitely a better answer than anything suggesting kill or any of its variants.
– TJ LuomaMar 30 at 2:58

@TJLuoma I think if you select the correct signal, then pkill is as graceful as any other method. I too favour the AppleScript, though created a function quit to make it breezy. However, if creating an AppleScript process isn’t necessary, pkill -QUIT -x Slack should be fine.
– CJKApr 17 at 20:50

Since I don't yet have the reputation to comment, I'm saying this as a separate answer. pkill without any flags does not match a specific process! For example, running pkill foo would target processes named foo, but would also target processes named foobar. This is because it uses regular expressions.

If you wish to kill a specific process, you can pass it the -x flag. For example, pkill -x foo. This will use exact names instead of regular expressions.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

kill sends a signal to terminate the app. It is not necessary to use -9 (kill) if the application is responding. You risk to loose unsaved data
– MatteoMar 28 at 17:58

Similarly, if you did happen to want to kill, say, all 5 instances of some named process, you could filter the output of ps on the CMD value and then kill all the first entries on those lines.
– Carl WitthoftMar 29 at 14:59

1

@Carl Witthoft, you can simply use killall procname, e.g. killall Slack and it will kill all occurrences of Slack or whatever procname is. No need to use ps!
– user3439894Mar 29 at 22:26

So, pgrep is a nice command that combines ps and grip.
– HarvApr 3 at 0:47