如何在 Mac 上查找和停止进程

cod*_*ing 13 unix process macos

如何在 Mac 上找到进程 ID 并停止在端口 8080 上运行的进程?

在 Ubuntu 上,这有效:

ps -aux
Run Code Online (Sandbox Code Playgroud)

我可以找到进程并运行:

kill -9 pid
Run Code Online (Sandbox Code Playgroud)

ps -aux 似乎不起作用,我如何在 Mac OS X Lion 上执行此操作?

Gor*_*son 18

由于历史原因,ps的选项是一团乱麻且不一致。在 OS X Lion 上,其中任何一个都应该可以工作:

ps -ax
ps -e
ps aux # this displays in a different format
Run Code Online (Sandbox Code Playgroud)

我没有方便测试的 ubuntu 框,但根据手册页ps -aux这也不是正确的方法:

Note that "ps -aux" is distinct from "ps aux". The POSIX and UNIX
standards require that "ps -aux" print all processes owned by a user
named "x", as well as printing all processes that would be selected by
the -a option. If the user named "x" does not exist, this ps may
interpret the command as "ps aux" instead and print a warning. This
behavior is intended to aid in transitioning old scripts and habits. It
is fragile, subject to change, and thus should not be relied upon.
Run Code Online (Sandbox Code Playgroud)


小智 9

如果您想查找并终止所有符合字符串的进程,您还可以在 Mac OSX 上使用以下命令:

ps aux | grep <string> | awk '{print $1}' | <sudo> xargs kill -9
Run Code Online (Sandbox Code Playgroud)

基本上这会做的是它会找到(grep)当前在您的系统上运行的所有进程匹配过程。

仅当当前用户没有终止进程的某些权限并且您在系统上具有 SUDO 访问权限时才使用 SUDO。


gad*_*tmo 5

使用Activity Monitor.

Applications-> Utilities->Activity Monitor