ログアウト時に自動実行された.desktopアプリケーションは終了しません。

ログアウト時に自動実行された.desktopアプリケーションは終了しません。

私がフォローしている答え起動時に自動起動.desktopアプリケーションが機能しません。、うまく動作します。 Pythonスクリプトを起動しています。アプリケーション.desktopは次のとおりです。

[Desktop Entry]
Type=Application
Name=Autostart Script
Exec=shutdown_notify.py
Icon=system-run

これはうまくいきます。ただし、ログアウトしてログインすると、スクリプトの最初のインスタンスがまだ実行されていることがわかります。

$ ps -C shutdown_notify.py
  PID TTY          TIME CMD
 4026 ?        00:00:01 shutdown_notify
25421 ?        00:00:00 shutdown_notify

ログアウト時にスクリプトを終了させる方法はありますか?終了ロジックを追加する必要がありますか?


logind.conf@binarystaのリクエストに応じて更新

$ grep -E 'KillUserProcesses|KillOnlyUsers|KillExcludeUsers' /etc/systemd/logind.conf
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root

更新、2つの自動起動ファイルがあります。 1つは上記のPythonスクリプトを起動し、もう1つはgnome-terminal再起動すると次のようになります。

$ ps aux | grep -E "gnome-terminal|shutdown_notify"
training  6495  0.9  0.1  84936 29360 ?        S    07:13   0:00 /usr/bin/python3 /usr/local/bin/shutdown_notify.py
training  6565  0.7  0.2 622880 34448 ?        Sl   07:13   0:00 /usr/lib/gnome-terminal/gnome-terminal-server
training  9647  0.0  0.0  13264  2564 pts/0    S+   07:13   0:00 grep --color=auto -E gnome-terminal|shutdown_notify

ログアウトしてログインすると、次のようになります。

training  6495  0.1  0.1  85076 29360 ?        S    07:13   0:00 /usr/bin/python3 /usr/local/bin/shutdown_notify.py
training 19110  3.1  0.1  84936 29636 ?        S    07:15   0:00 /usr/bin/python3 /usr/local/bin/shutdown_notify.py
training 19141  2.3  0.2 696496 34584 ?        Sl   07:15   0:00 /usr/lib/gnome-terminal/gnome-terminal-server
training 19421  0.0  0.0  13264  2696 pts/0    S+   07:15   0:00 grep --color=auto -E gnome-terminal|shutdown_notify

ベストアンサー1

その理由はKillUserProcesses基本no的にUbuntu。この設定を有効にすると、ユーザーが完全にログオフしてもユーザープロセスは終了しません。ユーザーがログオフしたときにすべてのユーザープロセスが終了するようにこの動作を変更するには、それを設定してKillUserProcesses=yes再度/etc/systemd/logind.confログインします。

true現在の値(変更された値でなければならない)は、次のように確認できます。

busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager KillUserProcesses
b true

修正する

gnome-terminal(GUIアプリケーション)とプロセスshutdown_notify.pyの違いは、gnome-terminal-serverプロセスが実行されている他のすべてのX11プロセスと同じTTYにバインドされていることです。ログアウトすると、デスクトップ環境とWindowsシステム(x11)が終了するためgnome-terminal終了します。

おすすめ記事