You are not logged in.

#1 2014-01-05 14:10:26

phire
Member
Registered: 2014-01-05
Posts: 7

[Solved] Gently terminate X processes on shutdown

Hi,
I'm using xmonad started by startx.
When I shutdown using

systemctl poweroff

, all processes are killed, I guess because the X server is terminated before his children.
Is there an elegant way to wait for all processes running in X to close before shutting down?

I searched on google but could not find anything apart from using a DM like gnome.
Thanks!

Last edited by phire (2014-01-09 11:26:34)

Offline

#2 2014-01-06 00:59:01

ayekat
Member
Registered: 2011-01-17
Posts: 1,590

Re: [Solved] Gently terminate X processes on shutdown

Have you tried running the shutdown command from within Gnome? Because I can imagine that Gnome does some additional cleanup and session magic that Xmonad & Co. don't - but that's probably because you invoke the shutdown sequence from Gnome's interface instead of directly launching the low-level systemd shutdown (correct me if I'm wrong).

On the other hand, since systemd and Gnome are both fairly complex, there is the possibility of systemd notifying Gnome in case of a shutdown, and Gnome will do some high-level user interaction and block systemd's shutdown sequence. But that's just some blunt guessing.

What exactly is your definition of "gently"? Popup window warning about windows that are still open?

Because... perhaps the X server performs some kind of XKillClient() internally before shutting down, which would actually be the same as if you closed all your windows manually before shutting down the WM.


pkgshackscfgblag

Offline

#3 2014-01-06 01:32:54

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Solved] Gently terminate X processes on shutdown

I don't think that gnome specifically does that cleanup, but rather it is a task of the display manager.  I too have noticed this and in particular, I noticed that every time I shut down xcmenu would have a coredump.  So I installed lightdm and set up autologin.  This seems to have solved that issue, and I never even see the DM.  In fact, the startup is now cleaner since I no longer see the start of the TTY -> login -> X starting.

Offline

#4 2014-01-06 05:01:07

phire
Member
Registered: 2014-01-05
Posts: 7

Re: [Solved] Gently terminate X processes on shutdown

Hi,
I don't use gnome, sorry if that was not clear. I just launch xmonad from the .xinitrc file and startx.
By gently I mean for example if there are unsaved changes in an gedit window I get a prompt to save or discard them.

Installing a DM would probably solve this, but if possible I would prefer not to

Offline

#5 2014-01-06 05:09:03

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Solved] Gently terminate X processes on shutdown

I had been pretty dead set on not installing a DM as well.  But I figured that if I really wanted a graceful exit, that was probably going to be the easiest way to achieve it.  I had startx running from ~/.zprofile off of an autologin to getty@tty1, so setting up autologin on lightdm really isn't much different to what I had before.  The exception being that I now see no text from POST to i3, and it is actually slightly faster.

I'm not sure if save dialogs would pop up automagically, but if the program supports showing a dialog for unsaved work on a SIGTERM then it probably would.

Unfortunately, I have no idea how you might implement this without using a DM.  Every answer I have seen the the past has been to just use a DM if this functionality is desired.  Sorry.

Offline

#6 2014-01-06 05:13:29

phire
Member
Registered: 2014-01-05
Posts: 7

Re: [Solved] Gently terminate X processes on shutdown

Yes, that is exactly how my setup is right now.
I just found a solution: http://superuser.com/questions/635166/w … ons-nicely
It is not SIGTERM or any other kill signal like i thought, but an X event that can be sent like

wmctrl -ic ID

I'll see if I write a script that does this for all windows and waits, or if I'll install lightdm.
Thanks

Last edited by phire (2014-01-06 14:25:08)

Offline

#7 2014-01-06 05:48:16

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Solved] Gently terminate X processes on shutdown

I think that the 'c' flag of wmctrl just sends a 'kill -15' (which is a SIGTERM) and provides a graceful exit if possible. 

I installed wmcrtl to see about using it to get the PIDs of the running X windows, and I get:

$ wmctrl -l
Cannot get client list properties. 
(_NET_CLIENT_LIST or _WIN_CLIENT_LIST)

Offline

#8 2014-01-06 14:24:04

phire
Member
Registered: 2014-01-05
Posts: 7

Re: [Solved] Gently terminate X processes on shutdown

No, I specifically tried sending SIGTERM to gimp and gedit. They both simply exit losing changes.

That error is probably because xmonad does not have a list of windows accessible to other programs. I'm using the EwmhDesktops extension which supports that, so it works for me.

I can just think of looping through the wmctrl output and waiting until there are no more outputs, any other ideas?

Offline

#9 2014-01-06 16:59:18

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Solved] Gently terminate X processes on shutdown

I think a loop seems like a sane solution.  Assuming that there are no potential save dialogs to be popped up, it should get through it pretty fast anyway.

phire wrote:

That error is probably because xmonad does not have a list of windows accessible to other programs. I'm using the EwmhDesktops extension which supports that, so it works for me.

Admittedly, I didn't dig into it whatsoever.  But I think it is interesting because I am an i3 user, and i3 is ewmh compliant.  Odd, but oh well.

No, I specifically tried sending SIGTERM to gimp and gedit. They both simply exit losing changes.

Interesting, thanks for the info.  I actually don't frequently use any programs that actually require a save dialog anymore.  I don't do photo editing much (if at all) and I use vim for pretty much anything I can.

Offline

#10 2014-01-06 18:04:43

rebootl
Member
Registered: 2012-01-10
Posts: 431
Website

Re: [Solved] Gently terminate X processes on shutdown

I know it's not exactly the question but just as a suggestion: Why not hibernate instead of shutdown.
Solves your shutdown and boot issues, is fast and absolutely equivalent to a poweroff (regarding power consumption) + your environment is the same as when you left it.

The only time you have to reboot is after a kernel update.


Personal website: reboot.li
GitHub: github.com/rebootl

Offline

#11 2014-01-06 19:12:41

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Solved] Gently terminate X processes on shutdown

@rebootl, IMO, hibernation on linux is spotty at best.  I have never been able to use hibernation without experiencing some kind of quirk.  Suspending to RAM on the other had works wonderfully on linux.  Still this doesn't address the issue at hand.  For those times that you do need to reboot, it would be nice to have something that provides a nice clean exit from running programs. 

Interestingly, the suggestion to not reboot is coming from a user with reboot in his/her username. smile

Offline

#12 2014-01-06 22:39:28

phire
Member
Registered: 2014-01-05
Posts: 7

Re: [Solved] Gently terminate X processes on shutdown

WonderWoofy wrote:

@rebootl, IMO, hibernation on linux is spotty at best.  I have never been able to use hibernation without experiencing some kind of quirk.

exactly.
This is why I don't even have swap anymore; it just never worked great.
Also, last time I tried it booting was faster (systemd-analyze says 2.8 seconds boot time)

What is the best way to start the .xinitrc session from lightdm? I just tried creating a .desktop with the XSession in it but then lightdm just crashed the whole system after boot

Offline

#13 2014-01-06 23:48:49

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Solved] Gently terminate X processes on shutdown

Well, from what I have gathered from my couple of days using lightdm, it uses desktop files to determine the available DE/WMs to allow logging into.  But ultimately, it uses /etc/lightdm/Xsession.  I have just left this Xsession file as is since I have a pretty plain .xinitrc.  But it is actually a protected file, so if you make changes to it, it won't be overwritten by pacman.

It appears that xmonad ships with a /usr/share/xsessions/xmonad.desktop file already, so in theory it should show up in the list of available dekstops to launch.  Can you elaborate on what it is you are trying to port from your .xinitrc to the Xsession file?  It should be enough to just copy the thing over.

Edit: By 'thing' I mean the snippet of the .xinitrc, not the whole file.

Last edited by WonderWoofy (2014-01-06 23:49:20)

Offline

#14 2014-01-07 16:02:28

phire
Member
Registered: 2014-01-05
Posts: 7

Re: [Solved] Gently terminate X processes on shutdown

okay, so it took me a while of tinkering but it seems to work now. The xmonad.desktop launcher did not work for me (i'm using xmonad from cabal-install), so I created a file /usr/share/xsessions/custom.desktop with

[Desktop Entry]
Name=xinitrc
Exec=~/.xinitrc

. Somehow, when I tried this with the lightdm-gtk-greeter it did not work and resulted in a restart loop of lightdm; but using kde-greeter now works.
I also start a few programs like chromium from .xinitrc
thanks for the help!

Offline

#15 2014-01-07 18:25:24

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [Solved] Gently terminate X processes on shutdown

Glad you got it working to your liking. smile

Did you also implement autologin?  I like it because I never actually see the DM at all (unless I exit i3).


Edit: Also, don't forget to mark the thread as [Solved] if you are satisfied with the result.  This can be done by editing the first post.

Last edited by WonderWoofy (2014-01-07 18:26:18)

Offline

#16 2014-01-09 11:35:27

phire
Member
Registered: 2014-01-05
Posts: 7

Re: [Solved] Gently terminate X processes on shutdown

Mostly, programs still do not ask to save changes, but at least they are not apruptly killed (mpd retains it's status now etc.). But by now I have already accustomed to just closing my windows before shutting down wink

Yes, I do have autologin with starting slock so I still need to enter my password now

Offline

Board footer

Powered by FluxBB