How to regain access to running applications after accidentally zapping X.org

xorg

I just accidentally hit CtrlAltBackspace. This apparently zapped the X server. After a short flash of the screen, my window manager asked me to log in again, and I was returned to a blank slate. A quick ps -ax showed that my applications were still running, but I didn't know how to bring them back to the foreground. (fg <foo> didn't.)

How can I regain access to running applications after accidentally zapping X.org?

Config: Free BSD 11.2, i3-4.16, xorg-7.7_3.

Best Answer

After zapping the X11 server and logging in again, the UNIX X11 socket in /tmp/.X11-unix/X0 has been deleted and recreated, and the X11 session cookie in ~/.Xauthority has been replaced with a new random cookie.

Even if the value of the DISPLAY environment variable is the same, the applications would have to close and re-open the socket and re-read the cookie. As far as I know, there is no generic mechanism to signal any X11 applications to do that. And that would be just the first step: after that, the applications would have to fully recreate all their windows and other GUI objects with the X11 server and restore their state to match the program's internal state. I'm afraid this functionality does not exist.

The best you can probably do is to use kill -HUP to stop the applications, giving them a chance to auto-save any unsaved work if they have been programmed to do that, and then restart them as normal.

(That actually matches exactly the original meaning of the HUP signal: it originally meant that the user's landline modem connection had been hung up, and the application should save any unsaved work in some way that allows it to be recovered in a new session, and then exit.)

Related Question