Skip to content

Launching Programs: dmenu_run and process groups?

May 4, 2012

Update 06-May-2012: I’ve been reading the mailing list to see if this has come up before, and there is a lengthy thread on improving dmenu_run. From what I can tell, the examples for improvement all had some sort of  “exec” call in them (but did not seem the focus of the discussion).  Looking through the revisions, it looks like dmenu_run did use ‘exec’ but called it on a shell, but this was changed for the purpose of “disowning the child shell.” The only thing I can think is perhaps this is due to a difference in how dmenu_run is invoked…

I just moved back to i3 from wmii, and after using it for a bit, I noticed that after launching programs with dmenu_run that they all were running under zsh (my SHELL) in pstree.

I remember wmii would launch the program as it’s own process. I like zsh in interactive uses, but it is a bit heavy wait to be used for just spawning processes. Luckily, dmenu_run uses ${SHELL} for launching, so I just made my keybinding launch “SHELL=dash dmen_run …” instead of plain “dmenu_run …” This worked nicely as it used dash to launch the program and took up much less memory.

But then, I thought why would dmenu_run launch programs this way? Wouldn’t it be a better idea to launch an application in it’s own group, say with the ‘exec’ function? The only reason I could think not to was the ability to use dmenu_run as a kind-of “one-off” shell. I’m not an expert on ‘exec’, but I was testing it out, and it still gave the same functionality. So, I made a modified dmenu_run called dmenu_exec, that just prepends “exec” to whatever it pipes to the shell. So far, it seems to be working as expected, and still allows me to use dmenu_run as a “one-off” shell.  And because I’m still piping this to a shell to run, I left the SHELL=dash line in my keybinding.

From what I understand about process groups, this seems to be a better way to launch programs, but as it isn’t what the dmenu developers did (and they seem like a pretty smart bunch), I wonder if there is something I’m missing. I’m using this for now, but any comments would be appreciated.

if [ -d "$cachedir" ]; then
    cache=$HOME/.dmenu_cache # if no xdg dir, fall back to dotfile in ~
    if stest -dqr -n "$cache" $PATH; then
        stest -flx $PATH | sort -u | tee "$cache" | dmenu "$@"
        echo "exec $(dmenu "$@" < "$cache")"
) | ${SHELL:-"/bin/sh"} &

From → Howto

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s