Function: proced-send-signal

proced-send-signal is an interactive and byte-compiled function defined in proced.el.gz.

Signature

(proced-send-signal &optional SIGNAL PROCESS-ALIST)

Documentation

Send a SIGNAL to processes in PROCESS-ALIST.

PROCESS-ALIST is an alist as returned by proced-marked-processes. Interactively, PROCESS-ALIST contains the marked processes. If no process is marked, it contains the process point is on, SIGNAL may be a string (HUP, INT, TERM, etc.) or a number. After sending SIGNAL to all processes in PROCESS-ALIST, this command runs the normal hook proced-after-send-signal-hook.

For backward compatibility SIGNAL and PROCESS-ALIST may be nil. Then PROCESS-ALIST contains the marked processes or the process point is on and SIGNAL is queried interactively. This noninteractive usage is still supported but discouraged. It will be removed in a future version of Emacs.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/proced.el.gz
(defun proced-send-signal (&optional signal process-alist)
  "Send a SIGNAL to processes in PROCESS-ALIST.
PROCESS-ALIST is an alist as returned by `proced-marked-processes'.
Interactively, PROCESS-ALIST contains the marked processes.
If no process is marked, it contains the process point is on,
SIGNAL may be a string (HUP, INT, TERM, etc.) or a number.
After sending SIGNAL to all processes in PROCESS-ALIST, this command
runs the normal hook `proced-after-send-signal-hook'.

For backward compatibility SIGNAL and PROCESS-ALIST may be nil.
Then PROCESS-ALIST contains the marked processes or the process point is on
and SIGNAL is queried interactively.  This noninteractive usage is still
supported but discouraged.  It will be removed in a future version of Emacs."
  (interactive
   (let ((process-alist (proced-marked-processes)))
     (proced-with-processes-buffer
         process-alist
       (list (proced--read-signal (length process-alist)) process-alist)))
   proced-mode)

  (unless (and signal process-alist)
    ;; Discouraged usage (supported for backward compatibility):
    ;; The new calling sequence separates more cleanly between the parts
    ;; of the code required for interactive and noninteractive calls so that
    ;; the command can be used more flexibly in noninteractive ways, too.
    (unless (get 'proced-send-signal 'proced-outdated)
       (put 'proced-send-signal 'proced-outdated t)
       (message "Outdated usage of `proced-send-signal'")
       (sit-for 2))
    (setq process-alist (proced-marked-processes))
    (unless signal
      (proced-with-processes-buffer
          process-alist
        (setq signal (proced--read-signal (length process-alist))))))

  (let (failures)
    ;; Why not always use `signal-process'?  See
    ;; https://lists.gnu.org/r/emacs-devel/2008-03/msg02955.html
    (if (functionp proced-signal-function)
        ;; use built-in `signal-process'
        (let ((signal (if (stringp signal)
                          (if (string-match "\\`[0-9]+\\'" signal)
                              (string-to-number signal)
                            (make-symbol signal))
                        signal)))   ; number
          (dolist (process process-alist)
            (condition-case err
                (unless (zerop (funcall
                                proced-signal-function (car process) signal
                                (file-remote-p default-directory)))
                  (proced-log "%s\n" (cdr process))
                  (push (cdr process) failures))
              (error ; catch errors from failed signals
               (proced-log "%s\n" err)
               (proced-log "%s\n" (cdr process))
               (push (cdr process) failures)))))
      ;; use external system call
      (let ((signal (format "-%s" signal)))
        (dolist (process process-alist)
          (with-temp-buffer
            (condition-case nil
                (unless (zerop (process-file
                                proced-signal-function nil t nil
                                signal (number-to-string (car process))))
                  (proced-log (current-buffer))
                  (proced-log "%s\n" (cdr process))
                  (push (cdr process) failures))
              (error ; catch errors from failed signals
               (proced-log (current-buffer))
               (proced-log "%s\n" (cdr process))
               (push (cdr process) failures)))))))
    (if failures
        ;; Proced error message are not always very precise.
        ;; Can we issue a useful one-line summary in the
        ;; message area (using FAILURES) if only one signal failed?
        (proced-log-summary
         (format "Signal %s" signal)
         (format "%d of %d signal%s failed"
                 (length failures) (length process-alist)
                 (if (= 1 (length process-alist)) "" "s")))
      (proced-success-message "Sent signal to" (length process-alist))))
  ;; final clean-up
  (run-hooks 'proced-after-send-signal-hook))