Function: delete-process

delete-process is an interactive function defined in process.c.

Signature

(delete-process &optional PROCESS)

Documentation

Delete PROCESS: kill it and forget about it immediately.

PROCESS may be a process, a buffer, the name of a process or buffer, or nil, indicating the current buffer's process.

Interactively, it will kill the current buffer's process.

Other relevant functions are documented in the process group.

View in manual

Probably introduced at or before Emacs version 22.1.

Key Bindings

Shortdoc

;; process
(delete-process process)

Source Code

// Defined in /usr/src/emacs/src/process.c
{
  register struct Lisp_Process *p;
  bool mess = false;

  /* We use this to see whether we were called interactively.  */
  if (EQ (process, Qmessage))
    {
      mess = true;
      process = Qnil;
    }

  process = get_process (process);
  p = XPROCESS (process);

#ifdef HAVE_GETADDRINFO_A
  if (p->dns_request)
    {
      /* Cancel the request.  Unless shutting down, wait until
	 completion.  Free the request if completely canceled. */

      bool canceled = gai_cancel (p->dns_request) != EAI_NOTCANCELED;
      if (!canceled && !inhibit_sentinels)
	{
	  struct gaicb const *req = p->dns_request;
	  while (gai_suspend (&req, 1, NULL) != 0)
	    continue;
	  canceled = true;
	}
      if (canceled)
	free_dns_request (process);
    }
#endif

  p->raw_status_new = 0;
  if (NETCONN1_P (p) || SERIALCONN1_P (p) || PIPECONN1_P (p))
    {
      pset_status (p, list2 (Qexit, make_fixnum (0)));
      p->tick = ++process_tick;
      status_notify (p, NULL);
      redisplay_preserve_echo_area (13);
    }
  else
    {
      if (p->alive)
	record_kill_process (p, Qnil);

      if (p->infd >= 0)
	{
	  /* Update P's status, since record_kill_process will make the
	     SIGCHLD handler update deleted_pid_list, not *P.  */
	  Lisp_Object symbol;
	  if (p->raw_status_new)
	    update_status (p);
	  symbol = CONSP (p->status) ? XCAR (p->status) : p->status;
	  if (! (EQ (symbol, Qsignal) || EQ (symbol, Qexit)))
	    pset_status (p, list2 (Qsignal, make_fixnum (SIGKILL)));

	  p->tick = ++process_tick;
	  status_notify (p, NULL);
	  redisplay_preserve_echo_area (13);
	}
    }
  remove_process (process);
  if (mess)
    message ("Deleted process");
  return Qnil;
}