Mac でプロセスを見つけて停止する方法

Mac でプロセスを見つけて停止する方法

Mac のポート 8080 で実行されているプロセス ID を見つけて停止するにはどうすればよいですか?

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 コマンドでは 2 番目の列にあり、最後の列は AWK から引数を取得してプロセスを強制終了します。

現在のユーザーにプロセスを強制終了する権限がなく、システム上で SUDO アクセス権がある場合にのみ、SUDO を使用します。

答え3

使用Activity Monitor

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

関連情報