I'm following the answer of Autostarting .desktop application at startup not working, and it is working well. I'm launching a python script. The .desktop application looks like this:

[Desktop Entry]
Name=Autostart Script

This is working well - but if I log out and log in I see the first instance of my script is still running.

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

Is there a way to make sure the script exits on log out? Do I need to add logic to quit on log out?

Update with logind.conf info as requested by @binarysta

$ grep -E 'KillUserProcesses|KillOnlyUsers|KillExcludeUsers' /etc/systemd/logind.conf

Update, I have two autostart files: one launches the python script above, the other launches gnome-terminal. After a reboot I see:

$ 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

Log out, log in, and I see:

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
  • please provide grep -E 'KillUserProcesses|KillOnlyUsers|KillExcludeUsers' /etc/systemd/logind.conf
    – binarysta
    Jun 17, 2020 at 10:56
  • @binarysta I've updated the question with the results of the grep
    – russau
    Jun 17, 2020 at 20:58
  • While it'd be interesting to know the rationale behind the design of a system that autostarts user programs at login without (by default) shutting them down at logout, using systemd --user units instead of ~/.config/autostart/ desktop entries is likely to give you grater control and flexibility.
    – fra-san
    Jun 18, 2020 at 0:09

1 Answer 1


This is because KillUserProcesses is no by default in Ubuntu. This setting causes user processes not to be killed when the user completely logs out. To change this behavior in order to have all user processes killed on the user's logout, set KillUserProcesses=yes in /etc/systemd/logind.conf and re-login.

current value can be checked by (it should be true after change)

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


The difference here between gnome-terminal (GUI Application) and shutdown_notify.py processes is, gnome-terminal-server process bound to the same TTY as all other X11 processes running. By logging out, the desktop environment and windowing system (x11) will be terminated so thats why gnome-terminal will exit.

  • Thanks @binarysta. If I do something like Exec=gnome-terminal it does quit when I log out. Do you know what the distinction is between the python script and the terminal application is?
    – russau
    Jun 18, 2020 at 6:35
  • @russau what is ps aux | grep -E "gnome-terminal|shutdown_notify" after you login?
    – binarysta
    Jun 18, 2020 at 7:01
  • I just did exactly that experiment! I've updated the question with the results.
    – russau
    Jun 18, 2020 at 7:17
  • 1
    @russau I updated the answer.
    – binarysta
    Jun 18, 2020 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.