「systemctl stop」と「systemctl Kill」の違いは何ですか?

「systemctl stop」と「systemctl Kill」の違いは何ですか?

systemctl stopこれらとそしての違いは何ですかsystemctl kill

systemctl kill-9(SIGTERM)の代わりに(SIGKILL)などのプロセスへのカスタム信号送信をサポートしています-15。それでは、常に(SIGTERM)を送信するsystemctl killより一般的なバージョンの唯一の違いは何ですか?systemctl stopsystemctl stop-15

たとえば、systemctl stop()のような結果は次のようになりますsystemctl killssh.servicesshd

systemctl stop:

$ systemctl stop sshd
$ systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2021-11-08 09:09:32 CET; 1s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
  Process: 2086153 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
  Process: 2086154 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=0/SUCCESS)
 Main PID: 2086154 (code=exited, status=0/SUCCESS)

systemctl kill:

$ systemctl kill sshd
$ systemctl status sshd
● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2021-11-08 09:10:15 CET; 1s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
  Process: 2086486 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
  Process: 2086487 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=0/SUCCESS)
 Main PID: 2086487 (code=exited, status=0/SUCCESS)

ベストアンサー1

systemctl kill非常に似ており、kill信号のみを送信します(デフォルト= SIGTERM)。killとの主な違いsystemctl killは、PIDの代わりに単位を指定することができ、systemdはその信号を送信したいプロセスを理解することです。

一方、systemctl stopコマンドラインで指定されたデバイスは停止します。systemdすべてのExecStop=行(存在する場合)が最初に実行されます。プロセスが残っている場合は、KillMode=ルールを使用して処理します。その後は送信されますSIGTERM(変更可能KillSignal=)。設定するとSendSIGHUP=すぐにSIGHUPを送信します。プロセスがSIGTERMを正しく処理できず、90秒以内に停止できない場合は、TimeoutStopSec=SIGKILL(変更可能)を送信します(変更可能)FinalKillSignal=。またKillMode=control-group、(デフォルト)の場合、すべての子プロセスも終了します。

systemctl killだから、これが単に信号を送ることであることがわかります。これによりデバイスが停止する可能性がありますが、systemdはこれが発生することを保証しません。代わりに、systemctl stop1つのデバイスが停止します。


systemctl kill次の仮定と同じですsystemctl stop

  1. いいえExecStop=
  2. KillSignal=ユニットファイルの--signal=
  3. デバイスは最初の信号(ハングしない)への応答が保証され、その後の作業は必要ありません。
  4. KillMode=設定されていないか等しいprocess

sshd.serviceの特別な点は、次のものが含まれることです。

ExecReload=/usr/sbin/sshd -t
ExecReload=/bin/kill -HUP $MAINPID

この場合、次のように質問できます。これら2つのコマンドの違いは何ですか?

# systemctl reload sshd
# systemctl kill --signal=SIGHUP --kill-who=sshd.service

ほぼ同じですが、違いは非常に明白です。信号の前に呼び出されますreload/usr/sbin/sshd -t


sshd.serviceのもう1つの特別な点は、孤立プロセスがsystemdによってクリーンアップされていないため、より密接に近づくことKillMode=processです。デフォルトでは、systemdは孤立したすべての子プロセスをクリーンアップします。systemctl killsystemctl stopKillMode=control-group

おすすめ記事