[xmonad] Avoiding multiple status bar processes after XMonad restart

Jacek Generowicz jacek.generowicz at cern.ch
Sun Jan 15 01:17:06 CET 2012


Brandon Allbery wrote:
> 
> If you're using a pipe

Yup.

> and writing to it in the logHook,

Yup.

> then the child xmobar will close automatically when xmonad restarts.

Err, Nope. At least not here it doesn't:

me at mybox:~$ head -n 154 .xmonad/xmonad.hs | tail -n 10
main = do
  xmobarPipe <- spawnPipe "xmobar"
  dzenPipe <- spawnPipe "dzen2 -p -x -0"
  xmonad myConfig 
   { 
    logHook = 
       updatePointer (Relative 1 1)
       >> (dynamicLogWithPP $ myDzenPP { ppOutput = hPutStrLn dzenPipe })
       >> (dynamicLogWithPP $ myXmobPP { ppOutput = hPutStrLn xmobarPipe })
   }
me at mybox:~$ xmonad --recompile
me at mybox:~$ killall xmobar dzen2
me at mybox:~$ ps ax | grep dzen2 | grep -v sh | grep -v grep | wc -l; ps ax | grep xmobar | grep -v sh | grep -v grep | wc -l
0
0
me at mybox:~$ xmonad --restart
me at mybox:~$ ps ax | grep dzen2 | grep -v sh | grep -v grep | wc -l; ps ax | grep xmobar | grep -v sh | grep -v grep | wc -l
1
1
me at mybox:~$ xmonad --restart
me at mybox:~$ ps ax | grep dzen2 | grep -v sh | grep -v grep | wc -l; ps ax | grep xmobar | grep -v sh | grep -v grep | wc -l
2
2
me at mybox:~$ xmonad --restart
me at mybox:~$ ps ax | grep dzen2 | grep -v sh | grep -v grep | wc -l; ps ax | grep xmobar | grep -v sh | grep -v grep | wc -l
3
3

> spawnPipe is not the same thing as spawn, it creates a communication
> channel and that is not useful and may be counterproductive if you
> aren't communicating with the xmobar.

which is what "ppOutput = hPutStrLn statusbarPipe" should be doing
(and I'm pretty sure it works, as the status bars *are* getting data
all the time).

(What would be the point of having an xmobar, if you (xmonad) aren't
communicating with it? (Or, rather than "not communicating" do you
mean "communicating with it via stdin rather than a pipe"?))

> (In particular, if xmobar isn't reading from the pipe because you
> didn't include a StdinReader in its config, it will never notice
> when that pipe gets closed.)

Don't you mean PipeReader, if we started it with spawnPipe? And
presumably StdinReader would be used with the startupHook version you
suggested?

In any case, I had neither StdinReader nor PipeReader in my xmobar
config. StdinReader doesn't fix it, and PipeReader is for named pipes,
which is not what spawnPipe creates, so I wouldn't know how to
configure one for this case.

Obviously I'm still missing something.

Thanks for all your input, it's making all sorts of things clearer.



More information about the xmonad mailing list