systemctl stop
これらとそしての違いは何ですかsystemctl kill
?
systemctl kill
-9
(SIGTERM)の代わりに(SIGKILL)などのプロセスへのカスタム信号送信をサポートしています-15
。それでは、常に(SIGTERM)を送信するsystemctl kill
より一般的なバージョンの唯一の違いは何ですか?systemctl stop
systemctl stop
-15
たとえば、systemctl stop
()のような結果は次のようになりますsystemctl kill
。ssh.service
sshd
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 stop
1つのデバイスが停止します。
systemctl kill
次の仮定と同じですsystemctl stop
。
- いいえ
ExecStop=
KillSignal=
ユニットファイルの--signal=
。- デバイスは最初の信号(ハングしない)への応答が保証され、その後の作業は必要ありません。
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 kill
systemctl stop
KillMode=control-group