자동 시작 .desktop 애플리케이션이 로그아웃 시 종료되지 않음

Jun 17 2020

Autostarting .desktop application at startup not working 의 답변을 따르고 있으며 잘 작동하고 있습니다. 파이썬 스크립트를 실행하고 있습니다. 응용 프로그램 은 .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

업데이트, 두 개의 자동 시작 파일이 있습니다. 하나는 위의 파이썬 스크립트를 시작하고 다른 하나는 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 binarysta Jun 18 2020 at 12:56

이는 기본적으로 우분투KillUserProcesses 에 있기 때문 입니다 . 이 설정을 사용하면 사용자가 완전히 로그아웃해도 사용자 프로세스가 종료되지 않습니다. 사용자 로그아웃 시 모든 사용자 프로세스가 종료되도록 이 동작을 변경하려면 설정 하고 다시 로그인하십시오.noKillUserProcesses=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에 바인딩된 프로세스입니다. 로그아웃하면 데스크탑 환경과 윈도우 시스템(x11)이 종료되므로 gnome-terminal종료됩니다.