Race conditions and ampersands

Every now and then my background image does not load and Openbox starts with a gray background. I suspect a race condition with startup events. This is my ~/.config/openbox/autostart file:

# compositor - background process + disable shadowing effects during session
picom -CGb &
# notifications
/usr/bin/dunst &
# panel - taskbar, system tray, battery, clock
tint2 &
# network manager
nm-applet &
# Autostart
dex -a -s /etc/xdg/autostart/:~/.config/autostart/ &
# Set display from arandr saved script
sh ~/.screenlayout/monitor.sh &
# Polkit
/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 &
# Wallpaper
nitrogen --restore &
# Low battery notifier
#~/.config/openbox/scripts/low_bat_notifier.sh &
# Start redshift and put an icon in the systray
redshift-gtk &

While searching for a fix I ran across a discussion that included when and if ampersands are needed.

Openbox Autostart Troubles

Relevent parts of the discussion:

Replier to OP’s original autostart question:

Are you sure all those ampersands are necessary? Run each command in a terminal and only add an ampersand in the autostart file if the prompt is not returned, this will help avoid any potential race conditions. I know for sure that picom shouldn’t have both an ampersand and the -b option applied at the same time.

Op’s response

As for the ampersands, I was following the Arch man page for Openbox

Replier’s response

In this case the man page is incorrect — adding ampersands where they are not needed can precipitate race conditions. An ampersand is only needed if the command does not return the prompt after it is run in a terminal.

Now the $1000 questions:

  1. Are ampersands required to end every command line in a startup or autostart script?

  2. Will they possibly start a race condition if not needed?

I removed the ampersand from the picom line and the problem of nitrogen not starting a background image seems to have disappeared. But that is just anecdotal and no real data to back it up.

No. Only for things that need to be forced into the background


Basically when you run those commands they aren’t waiting for any of the other commands to finish. So if the order they start doesn’t matter then all is good. However, if some of the need to finish starting before others can start, you need to manage that somehow.


I used sleep. For example,

(hsetroot -tile $HOME/Backgrounds/gray.png) &
(sleep 2s && tint2) &
(sleep 3s && $HOME/bin/cpu-usage-alert) &
(sleep 3s && lxclipboard) &
(sleep 3s && compton --config $HOME/.config/compton.conf -b) &
(sleep 5s && pkill update-notifier) &
1 Like