I have my .bash_profile configured to launch emacs, and usually the first time it tries to, nothing happens, the command shows up in my "log file" but I don't get an emacs, but then if I start another copy, it launches emacs. It doesn't matter whether I close the first session or not for the second attempt to work.
Here are the relevant commands from my .bash_profile. They are essentially the end of it.
echo emacs --debug-init -mm >> ~/emacs-messages/inside-emacs
emacs --debug-init -mm
echo sleep 1 >> ~/emacs-messages/inside-emacs
sleep 1
echo emacs should be running now >> ~/emacs-messages/inside-emacs
echo ps -ax >> ~/emacs-messages/inside-emacs
ps -ax >> ~/emacs-messages/inside-emacs
Now, when it works, I see the result of the first echo line in the file and emacs is running. When it doesn't I see all the echo lines in the file and there is no emacs process running. I can then start emacs manually with the same command as in the .bash_profile, but for some reason bash has not let me start it automatically. By the way, I execute these commands only when ${DISPLAY} is set (and it is always ":0". My .emacs file also does logging and I don't see any of those messages when emacs doesn't start.
The problem only manifests itself under WSL 2, but doesn't matter which version of Ubuntu (i.e. 18.04 or 20.04) that I use. All of this is on Windows 10 pro, build 21390.co_release.210512-1658.
Also there is no effect (on the bad case) of backgrounding the emacs command, i.e.
emacs --debug-init -mm &
Same issue. It does get the sleep and other messages to appear in my log file in the good case, but that I don't care about. There is nothing interesting in that case, other than I see a running emacs process in the ps output.
If there is something else I should be logging to get information, I would appreciate knowing that also.