This is my first question with Ask Ubuntu, so I'd like to thank you in advance for your patience.

My situation is this: I have a *.desktop file (which I wrote) that is supposed to execute a shell script. My initial intent was to place this file in ~/.config/autostart so that it would run automatically at startup; however, this causes Ubuntu to flash the desktop for a split second, then log me back out. I can double click the file on my desktop and it will launch the script like it's supposed to. If I take the *.desktop file out of the ~/Desktop directory and put it literally anywhere else, double clicking it in Nautilus will also result in me being logged out immediately.

The *.desktop file is set to execute a shell script which starts bash in gnome-terminal. My reasons for doing this are not necessarily important, so please assume that that's the way I need it to be. If I add sleep 10 to the beginning of the first shell script, I am logged out 10 seconds after starting the *.desktop file, regardless of how it is started. It seems like the problem is in the fact that a new gnome-terminal window is started from the second script, but I don't understand how or why this would be. Desktop entry:

[Desktop entry]
Comment=Starts autocap program


nohup gnome-terminal --title=Autocapture --maximize -e "bash -c 'bash /Autocapture/Startup/StartAutocap.sh';bash"
wmctrl -a "Autocapture"           # Give focus to new terminal window
kill -9 $PPID                     # Close this terminal


source /usr/local/bin/virtualenvwrapper.sh
workon Autocap
python /path/to/python/module.py

This is supposed to (and successfully does, if launched from desktop) start a fullscreen gnome-terminal window running bash and launch the "module.py" program in that bash session. It also closes the first gnome-terminal window that started and detached the child process.

Sorry for the incredibly long first post. I just want to understand what is going wrong here and how I might be able to fix it. Any help is greatly appreciated!

1 Answer 1


While I have my theories, I am afraid to proclaim that I know exactly (or even remotely) how or why this works. I would imagine that it has something to do with the way a *.desktop launcher executes its target. Perhaps I was trying to kill the gnome-terminal window after it had already been closed at the end of the script's execution and ended up killing my session? Maybe vice versa? I don't claim to know, but I would invite anyone who does to please answer this question with your explanation so that others may learn from my mistake.

Removing the line kill -9 $PPID solved the problem

If the script is executed from the *.desktop launcher, the initial gnome-terminal window will close, leaving the second. If the script is executed from the command line (for example, $ bash InitSystem), the initial gnome-terminal window does not close.

  • I think when one terminal window is closed all the processeses connected to the other end of the terminal get the SIGHUP signal, which by default terminates the process. Jun 4, 2018 at 21:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .