What is the difference between exec and dbus-launch

d-busexec

If I start a process, particularly at session start, what is the difference between using exec p and dbus-launch p?

Best Answer

dbus-launch is DBus-related. exec is a shell built-in. See their manpages/help pages:

dbus-launch - Utility to start a message bus from a shell script.
exec - Replace the shell with the given command.

So... they basically do two different things... While both are expected to start program p passed as a parameter, you can read that in the case of dbus-launch, a few other things are done first:

You may specify a program to be run; in this case, dbus-launch will launch a session bus instance, set the appropriate environment variables so the specified program can find the bus, and then execute the specified program, with the specified arguments.

In this case, a DBus daemon instance is created prior to creating the process, and it should be running a secondary session bus, which is made available to the child process through environment variables.

Also note that in the case of exec, the current shell is replaced by a new program. dbus-launch will not replace the shell, and nor will the program you start alongside the daemon.