終了したプロセスIDをstdoutとして印刷します。

終了したプロセスIDをstdoutとして印刷します。

コマンドを使用して終了したバックグラウンドプロセスのプロセスIDkillで印刷する方法はありますか?stdoutGoogleで検索してみると、オプション(一部のUnixまたはLinuxの場合)があるようですが、--verboseUbuntu 20.xまたはCentOS 7.xでは利用できないようです。

コマンドだけでは実行できない場合は、killCLIを介して他の方法(コマンドやkill他のコマンドを使用)で実行できますか?

以下は、バックグラウンドプロセスを終了するために使用するコマンドの例です。

kill $(jobs -p)

この例を実行すると、可能であれば終了するプロセスIDが表示されます。

私がインターネットで見つけたものは次のとおりです。

To enable verbose logging pass the --verbose flag to the kill command. 
Note that this is not supported by all shell built-ins so may not be available on your system.
    
    kill --verbose 17146
    sending signal 15 to pid 17146

追加情報:

/usr/bin/kill --verbose 8411
Usage:
 kill [options] <pid|name> [...]
Options:
 -a, --all              do not restrict the name-to-pid conversion to processes
                        with the same uid as the present process
 -s, --signal <sig>     send specified signal
 -q, --queue <sig>      use sigqueue(2) rather than kill(2)
 -p, --pid              print pids without signaling them
 -l, --list [=<signal>] list signal names, or convert one to a name
 -L, --table            list signal names and numbers
 -h, --help     display this help and exit
 -V, --version  output version information and exit
For more details see kill(1).

だから私のシステムでは明らかに使用できません。解決策や同等の解決策に関する提案はありますか?

解決策:jobs -p | xargs -t kill

ベストアンサー1

kill内蔵シェルです

   $ type -a kill

    kill is a shell builtin
    kill is /usr/bin/kill

使用するにはコマンドを--verbose呼び出す必要がありますkill

   $ /usr/bin/kill --verbose 4935

    sending signal 15 to pid 4935

SUSE 12(util-linux 2.33.2)とCentos 8(util-linux 2.32.1)を確認しましたが、 verbose有効なオプションです。おそらく、ディストリビューションがkill別のフラグにコンパイルされた可能性があります。回避策として、-pロギング目的でのみ実行できますprints the pids

/usr/bin/kill --help

Usage:
 kill [options] <pid>|<name>...

Forcibly terminate a process.

Options:
 -a, --all              do not restrict the name-to-pid conversion to processes
                          with the same uid as the present process
 -s, --signal <signal>  send this <signal> instead of SIGTERM
 -q, --queue <value>    use sigqueue(2), not kill(2), and pass <value> as data
 -p, --pid              print pids without signaling them
 -l, --list[=<signal>]  list signal names, or convert a signal number to a name
 -L, --table            list signal names and numbers
     --verbose          print pids that will be signaled

 -h, --help             display this help
 -V, --version          display version

おすすめ記事