Shell – Start new process group in .xinitrc

processprocess-groupsshellxinit

I have a statusbar (lemonbar) to which I pipe the output of a couple of scripts (time, battery, volume, etc.). These scripts, and the statusbar itself, are all started in a single bash script statusbar. When the statusbar process is killed, it cleans up after itself by attempting to kill its children, like so:

trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

This all works fine if I call statusbar in a terminal, and then quit it with a SIGTERM signal.

However, when I start statusbar in my .xinitrc file like this: statusbar &, the statusbar script is not able to clean up after itself anymore. The reason for this is that it is in the same process group as the .xinitrc script, together with all the other processes that are started there. I discovered this by following this answer.

The question is: can I put the statusbar process and all its children in their own process group from .xinitrc, so that it can clean up after itself nicely? Alternative, maybe there is a different way of killing all the children of statusbar?

P.S.: I realize that wanting to cleanly kill a statusbar is not very common. However, I would like to do it so that I can restart it easily and eventually change my colour theme dynamically, without having to exit X.

Best Answer

You can try using setsid (part of the util-linux package) in the .xinitrc to start the script in a new session:

setsid statusbar

but will it still receive your signals?

Related Question