I made a line:

[[ -z $DISPLAY && $XDG_VTNR -le 4 ]] && exec startx

(right out of the Arch Wiki) at the end of .xinitrc to start the Xserver right after login on console.

Whenever I'm ending the session, daemons started in .xinitrc will not be killed when logging out, regardless of using bash or zsh.

It seems as if .bash_logout/.zlogout are not being parsed, basically just holding:

kill -15 -1 &&

Anyone else having that problem and maybe a solution?


The exec builtin replaces the shell by the specified program. After that point, the shell is no longer around to load .*logout.

In any case, the shell that runs .xinitrc is not a login shell, so it wouldn't run any .*logout file — but that shell is not where you would run startx anyway, it's a file that's loaded from xinit which is executed by startx.

If you want to run something after logging out of the graphical session, you need to keep the shell running and specify something to run after startx. Assuming that the exec startx line is in .profile or a similar file executed by your login shell, you need to keep the shell running while the X session is active, then exit (so as not to follow the GUI session by an interactive shell).

if [[ -z $DISPLAY && $XDG_VTNR -le 4 ]]; then
  if startx; then
    # We just exited an X session.
    # If your login shell is bash, it runs ~/.logout at this point.
    echo >&2 "The X session aborted with an error, dropping to a text shell"
  • Thanks a lot, very helpful! I had a look into man exec now, one just need to know where to look. I can't upvote right now because of a low reputation, this has been my first question here. – Mono May 11 '15 at 9:19
  • @Mono exec is a shell builtin, so you need to look in your shell's manual (e.g. bash — the basics are the same in all shells). – Gilles May 11 '15 at 9:33
  • @Gilles Ah, alright. Found it in man bash and man zshbuiltins now. One just need to.. Thanks again :-) I tried the line without exec, just && xinit -- :0 -nolisten tcp vt$XDG_VTNR, which worked, dropping me back to console when Xserver stops, regardless of reason. I will try your loop now, which provides easy logout. – Mono May 11 '15 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.