Function: nrepl--kill-process

nrepl--kill-process is a byte-compiled function defined in nrepl-client.el.

Signature

(nrepl--kill-process PROC)

Documentation

Attempt to kill PROC tree.

On MS-Windows, using the standard API is highly likely to leave the child processes still running in the background as orphans. As a workaround, an attempt is made to delegate the task to the `taskkill program, which comes with windows since at least Windows XP, and fallback to the Emacs API if it cant be found.

It is expected that the `(process-status PROC)` return value after PROC is killed is `exit` when `taskkill` is used and `signal` otherwise.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260414.1619/nrepl-client.el
;;; Client: Process Handling

(defun nrepl--kill-process (proc)
  "Attempt to kill PROC tree.
On MS-Windows, using the standard API is highly likely to leave the child
processes still running in the background as orphans.  As a workaround, an
attempt is made to delegate the task to the `taskkill` program, which comes
with windows since at least Windows XP, and fallback to the Emacs API if it
can't be found.

It is expected that the `(process-status PROC)` return value after PROC is
killed is `exit` when `taskkill` is used and `signal` otherwise."
  (cond
   ((and (eq system-type 'windows-nt)
         (process-live-p proc)
         (executable-find "taskkill"))
    ;; try to use `taskkill` if available
    (with-temp-buffer
      (call-process-shell-command (format "taskkill /PID %s /T /F" (process-id proc))
                                  nil (buffer-name) )
      ;; useful for debugging.
      ;;(message ":PROCESS-KILL-OUPUT %s" (buffer-string))
      ))

   ((memq system-type '(cygwin windows-nt))
    ;; fallback, this is considered to work better than `kill-process` on
    ;; MS-Windows.
    (interrupt-process proc))

   (t (kill-process proc))))