I just installed Ubuntu 14.04 beta2 and out of 25 tries either logging out, shutting down or restarting, my session didn't close Firefox properly 23 times when exiting. The result is the Firefox tabs recovery page that never happens if I take the time to close Firefox manually beforehand.

Since it worked 2/25 times, it feels like a time problem where Ubuntu doesn't allow Firefox's process time to end (Ubuntu logs out in about 1-2s). I've never even received the "wait for Firefox? / shut down anyway?" dialogue box that I observed under 12.04.

So if I'm correct, how do I make it so that it waits? If not what is the issue and how do I solve the improper exiting?

I have no experience with managing profile or session config files and very little with bash (I understand it but am lousy at coding it). So if you can't answer but have an good article on how does the profiles/sessions work in Unix/Linux/Debian/Ubuntu (if the same) and/or how to make changes to the login/logout events, I'd be happy with that.

Edit: I made additional tests that further indicate it's a matter of time

  • wmctrl -c firefox; sleep 0.5; sudo shutdown now -r works fine 100%
  • wmctrl -c firefox; sleep 0.2; sudo shutdown now -r works fine 50%
  • wmctrl -c firefox; sudo shutdown now -r works fine 10%
  • sudo shutdown now -r& wmctrl -c firefox never seems to work...

So as a workaround, how can I write wmctrl -c firefox; sleep 0.5 in a file that resembles .profile or bash_logout but for session logout?

  • The kernel isn't a patient man. The Firefox process may have taken too long to terminate after being (nicely) signalled the first time ; he probably received another (more radical) signal, and got roughly killed. This would mainly depend on the developers' job, not your system's configuration specifically. Commented Apr 17, 2014 at 17:04
  • @JohnWHSmith But I said it takes 2 seconds at most to log out. I just tried now again and it was instantaneous (0.1s). Logging in welcomed me again with an embarrassed Firefox. Also since it's a bug, do I report it on Ubuntu or the kernel or what then if as you say I really can't do anything myself?
    – sinekonata
    Commented Apr 17, 2014 at 17:17
  • 1
    I believe the bug report should go against Firefox. Firefox 28 seems to not behave as well as it used to; it sometimes stays running after all windows are closed, and spinlocks multiple CPU cores.
    – dobey
    Commented Apr 17, 2014 at 17:40
  • @dobey If what you say is true it must be extremely fast: I tested shutting down immediately (0.1s) after pressing the Firefox (x) button and no bug there. I feel like what Ubuntu does is close with a kill process command. I just want to restate that I have no add-on installed that everything is fresh and that it didn't happen in 12.04. All I want is for a way to call the "close properly action" instead of the "close abruptly" one.
    – sinekonata
    Commented Apr 17, 2014 at 18:11
  • Just because the window went away, doesn't mean Firefox has actually exited. Or it doesn't necessarily mean that it exited cleanly. For all we know, Firefox could be crashing when you exit it, and it has nothing to do with the logout/in process at all. Were you using the same Firefox 28 build in 12.04?
    – dobey
    Commented Apr 17, 2014 at 19:14

1 Answer 1


Apparently there is no dedicated file to write to like there used to be. It was the /etc/gdm/PostSession under Gnome but isn't available since apparently Unity. And placing a script under /etc/rc0.d/ and /etc/rc6.d/ will not work since they are only executed after Xserver is shut down.

However there is an event called gnome-save-yourself fired when gnome has been demanded to log out. I is what gedit for instance will implicitly call. And Seamus Phelan made a python script to listen to the event and run your script when caught.

Here's the link to the solution : Script Execution at user logout (non root user)

Follow instructions and then all you have to do is place your script that may look like this:

#! /bin/sh
#Requires wmctrl
wmctrl -c firefox;
gmusicbrowser -cmd "Quit";
exit 0;

where the option -c gently closes Firefox as does -cmd "Quit" for gMusicBroswer. Both Firefox and gMusicBrowser need to be closed properly which they do not.

A probably better way would be to check the use of SIGTERM, SIGKILL and kill timeout in Ubuntu and the programs but I don't know enough about it.


You must log in to answer this question.

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