Mac终端kill、killall命令:是正常退出还是强制退出?功能解析
Hey there! Let me break down your questions about macOS terminal kill and killall clearly—since you're on macOS 10.13.4 High Sierra, I’ll make sure this fits your system perfectly.
1. Is killall a normal Quit or Force Quit by default?
By default, killall sends the SIGTERM signal (signal 15) to processes. This is exactly like clicking Quit in the UI: it politely tells the app/program to shut down gracefully, giving it time to save your work, release system resources, or close any open connections properly.
If you add the -9 flag (e.g., killall -9 Safari), you’re switching to the SIGKILL signal. This is the terminal equivalent of Force Quit—the system yanks the process straight out of memory without letting it clean up. Only use this if the app is completely frozen and won’t respond to a normal quit!
2. What’s the difference between kill and killall?
kill
- Works with unique process IDs (PIDs). You first need to look up the PID of the process you want to terminate (use
ps auxortopin the terminal to find these numbers). - Defaults to sending
SIGTERM(graceful quit)—example:kill 1234where1234is the PID of your target process. - You can send other signals too: like
kill -HUP 1234to tell a process to reload its settings, orkill -9 1234to force it to shut down immediately.
killall
- Works with process names instead of PIDs. It will kill every running process with that exact name—so
killall Finderwill shut down all instances of the Finder app (handy when Finder is being glitchy). - Also defaults to
SIGTERMfor a clean shutdown. - Just like
kill, add-9to force termination if the process isn’t responding (e.g.,killall -9 Slackwhen Slack is stuck).
3. How do these commands map to the UI’s Quit/Force Quit?
- Default
kill/killall(no-9): Exactly the same as the UI’s Quit. Both sendSIGTERM, and well-behaved apps will respond by cleaning up and shutting down safely. This is the preferred way to terminate processes whenever possible. kill -9/killall -9: Identical to the UI’s Force Quit.SIGKILLskips all the process’s normal shutdown logic, so it’s a last resort. Using it can leave temporary files open or cause data loss, so only use it when the process is unresponsive to normal commands.
One quick heads-up: Some processes might ignore SIGTERM (usually if they’re stuck in an infinite loop or frozen). In those cases, the default kill/killall won’t work, and you’ll need to use -9—just like how you’d use Force Quit on a hanging app in the UI.
内容的提问来源于stack exchange,提问作者DavidT




