
如何在 Mac 上找到進程 ID 並停止在連接埠 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