I use browse-url/browse-url-firefox to open links in Firefox from within Emacs 24.5.1 under Linux (Fedora 23) which in essence executes the firefox executable with the URL by start-process. If there is already a Firefox instance running, this will in turn cause the URL to be opened in a new tab and terminate the firefox executable spawned from Emacs, but otherwise a new Firefox instance will be running as a process child of Emacs (for testing purposes, this is equivalent to M-! sleep 1h & RET).

If I then want to exit Emacs, it asks me "Active processes exist; kill them and exit anyway?" with the option to either kill the Firefox instance or, well, leave Emacs running. Instead I would like to "detach" the firefox process from the Emacs parent so that I can exit Emacs while keeping the Firefox instance running.

Is it possible to spawn processes from Emacs that "survive" exiting Emacs, or must all spawned processes die when Emacs exits?

  • Are you running Emacs on a Windows machine by any chance? It sounds similar to an issue I never got an answer to from about 2 years ago -- How to delete a process from Emacs without killing the subprocess: stackoverflow.com/q/19747637/2112489 On OSX, for example, the behavior is different -- i.e., I can open an external application with start-process (like a pdf viewer) and Emacs thinks its job has finished.
    – lawlist
    Commented May 19, 2016 at 2:48
  • No, I'm using Linux (Fedora 23). I'll amend the question to reflect that. Commented May 19, 2016 at 4:19

3 Answers 3


here's solution, shorting @abo-abo's answer.

     ((string-equal system-type "windows-nt") ; Windows
      // ...
     ((string-equal system-type "gnu/linux")
      (start-process "my-browse"
                     nil "setsid"
                     (concat "file://" buffer-file-name ))

      ;; (browse-url ξurl)
     ((string-equal system-type "darwin") ; Mac
                // ...

Note that condition is necessary, because Mac doesn't have setsid.

  • See the answer here for an updated answer that should also work for Mac's Commented May 27, 2021 at 15:31

Currently the best way to achieve this (although it does not work for Windows) is by using the command call-process with the destination argument set to 0 (see https://www.gnu.org/software/emacs/manual/html_node/elisp/Synchronous-Processes.html).

E.g. to start firefox you could use:

(call-process "firefox" nil 0 nil "www.spacemacs.org")
  • 1
    The parent process of (call-process "firefox" nil 0 nil "www.spacemacs.org") is Emacs, where as the parent process of (start-process "firefox" nil "setsid" "firefox" "www.spacemacs.org") is init, therefore using the later may be desired if you want to fully detach from Emacs from a process view point
    – John32ma
    Commented Apr 17 at 11:05

Here's a command that does what you want:

(defun ora-dired-start-process (cmd &optional file-list)
   (let ((files (dired-get-marked-files
                 t current-prefix-arg)))
      (unless (eq system-type 'windows-nt)
        (dired-read-shell-command "& on %s: "
                                  current-prefix-arg files))
  (if (eq system-type 'windows-nt)
      (dolist (file file-list)
        (w32-shell-execute "open" (expand-file-name file)))
    (let (list-switch)
       cmd nil shell-file-name
        "nohup 1>/dev/null 2>/dev/null %s \"%s\""
        (if (and (> (length file-list) 1)
                 (setq list-switch
                       (cadr (assoc cmd ora-dired-filelist-cmd))))
            (format "%s %s" cmd list-switch)
        (mapconcat #'expand-file-name file-list "\" \""))))))

(define-key dired-mode-map "r" 'ora-dired-start-process)

The key thing here is to use nohup.

See the source here.

  • Thanks! nohup is a nice solution. Unfortunately I find your answer too "distracting" for someone just looking for how to achieve the goal. Could you please trim the source down to something like (shell-command "nohup sleep 1h &") and add an explicit note that "detaching" from an existing process is not possible so that I can accept the answer? Commented May 22, 2016 at 4:36
  • I was told 'setsid' was better than 'nohup'.
    – YoungFrog
    Commented May 22, 2016 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.