Find the controlling program for your X session and write it down:
_____________________________ Program to quit last
If your controlling program is a terminal
window, we suggest
leaving that window minimized from just after you've logged in until
you've shut down all the other X programs.
That way, you won't end your X session accidentally by closing that
terminal window too soon.
No matter what your controlling program is, closing it sooner than last
means the other windows will be killed quickly and automatically.
There's a chance, though, that programs running in those killed
windows--especially if they're terminal windows--won't be
killed, and will keep running, disconnected from your login session.
So it's best to close the controlling program window last.