如何找到进程 ID 并停止在 Mac 上端口 8080 上运行的进程?
在 Ubuntu 上这是可行的:
ps -aux
我可以找到该进程并运行:
kill -9 pid
ps -aux
似乎不起作用,我该如何在 Mac OS X Lion 上执行此操作?
答案1
由于历史原因,ps
的选项很复杂且不一致。在 OS X Lion 上,以下任何选项都应该有效:
ps -ax
ps -e
ps aux # this displays in a different format
我手边没有 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.
答案2
如果您希望查找并终止所有符合字符串的进程,您也可以在 Mac OSX 上使用以下命令:
ps aux | grep <string> | awk '{print $1}' | <sudo> xargs kill -9
基本上,它将查找(grep)系统上当前正在运行的所有与匹配的进程,AWK 获取 PID,在 PS 命令中是第二列,最后一个从 AWK 获取参数并终止进程。
仅当当前用户没有终止进程的某些权限并且您在系统上具有 SUDO 访问权限时才使用 SUDO。
答案3
Applications
-> Utilities
->Activity Monitor
答案4
为了保持最新状态,对于 macOS:
ps -e | grep python | awk '{print "sudo kill -9", $1}' | sh
对于 Linux:
ps -ax | grep python | awk '{print "sudo kill -9", $1}' | sh