Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is just a small annoyance, but I've made the XMonad configuration file load xmobar using this code:

xmproc <- spawnPipe "/use/bin/xmobar ~/.xmobarrc"

It works well, but it spawn a new xmobar process every time XMonad is reloaded. I wonder if there's an easy way to kill the old one?

update: As suggested by entropo, I've created a bash script like this one:


for PID in `pgrep xmobar`; do
    kill ${PID} > /dev/null &

/usr/bin/xmobar &

and call that script from XMonad configuration file.

share|improve this question
up vote 4 down vote accepted

Not xmonad specific, but you could launch xmobar through a shell script that checks for an existing xmobar process. See, e.g.,

share|improve this answer

If you have a shell script to start XMobar then you are 'doing it wrong'. You should be starting xmobar using the correct Haskell functions in the xmonad.hs config source file. Take a look at my configs main function:

-- put it all together
main = do
    nScreens <- countScreens    -- just in case you are on a laptop like me count the screens so that you can go
    xmonad =<< xmobar myBaseConfig
      { modMask = myModMask
      , workspaces = withScreens nScreens myWorkspaces
      , layoutHook = myLayoutHook nScreens
      , manageHook = myManageHook
      , borderWidth = myBorderWidth
      , normalBorderColor = myNormalBorderColor
      , focusedBorderColor = myFocusedBorderColor
      , keys = myKeys
      , mouseBindings = myMouseBindings
      , logHook = myLogHook
        myLogHook = dynamicLogXinerama

myBaseConfig = gnomeConfig

The salient line is this one:

xmonad =<< xmobar myBaseConfig

That runs xmobar as it should be run, even when you reload xmonad. You get the 'xmobar' function from the statement:

import XMonad.Hooks.DynamicLog (xmobar)

Which in turn comes from the xmonad-contrib package.

So you see, most things that you want to do with XMonad are already a solved problem, you just have to know where to look. Basically, just ditch your script and use that instead. I hope this helps.

share|improve this answer
Well, I've found the spawnPipe code on the XMonad website, it's really not easy to know where to look! But in the end, I prefer the technique I'm using as it is cleaner, using DynamicLog didn't kill the old process in my tests. I really like XMonad, but Haskell is not a good configuration language. – Nicolas Buduroi Apr 10 '11 at 15:21
Okay, whatever works for you is good in the end. But I think you are thinking about it wrong. You do not configure XMonad: you extend it. Haskell the prefect fit for extension. – Robert Massaioli Apr 10 '11 at 23:00
For me this is creating 2 new processes each time I reload xmonad. Using spawnPipe creates 2 additional processes. ps -ax returns: "/bin/sh -c /.cabal/bin/xmobar ~/.xmobarrc:", "/bin/sh -c xmobar", "~/.cabal/bin/xmonad ~/.xmobarrc" and "xmobar". – fsanches Aug 1 '15 at 3:18
Reinstalling both fixed the issue in my commend above. – fsanches Aug 1 '15 at 3:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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