In a previous toot thread we've been talking about ways to launch processes from Emacs in a way that lets them survive Emacs exiting, crashing or restarting via M-x restart-emacs.
The best way I've found so far:
;;; with separate cmd and args:
(call-process command nil 0 args)
;;; or let the shell parse the command:
(call-process-shell-command command nil 0)
The key is the 0 as the third argument, this causes Emacs to discard the output and not wait for the process.
I use it like this for my EXWM command launcher function:
(defun my-exwm-run (command)
(interactive (list (read-shell-command "$ ")))
(call-process-shell-command command nil 0))
Previously I used start-process-shell-command and nohup but that accumulated defunct processes when using M-x restart-emacs. The call-process-shell-command with the 0 arg doesn't seem to have that problem and it doesn't need nohup. This is a bit counter intuitive because call-process is supposed to be for synchronous processes. Not sure if make-process (the async primitive) can do this the same way.
If somebody is familiar with how/why exactly this works I'd love to hear your thoughts.
#emacs #exwm