From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: have emacs use SIGTERM to end a process instead of SIGHUP Date: Mon, 15 Jul 2013 12:46:37 +0200 Message-ID: <87y598rtgy.fsf@thinkpad.tsdh.de> References: <51DB3A43.4090909@johnleach.co.uk> <87txk4c55k.fsf@thinkpad.tsdh.de> <51DFE1EE.2000805@johnleach.co.uk> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1373885229 31112 80.91.229.3 (15 Jul 2013 10:47:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 15 Jul 2013 10:47:09 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 15 12:47:10 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UygJ7-0003Iw-Sy for geh-help-gnu-emacs@m.gmane.org; Mon, 15 Jul 2013 12:47:06 +0200 Original-Received: from localhost ([::1]:51226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UygJ7-0002nI-J7 for geh-help-gnu-emacs@m.gmane.org; Mon, 15 Jul 2013 06:47:05 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UygIv-0002mu-D3 for help-gnu-emacs@gnu.org; Mon, 15 Jul 2013 06:46:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UygIs-0000gS-Ej for help-gnu-emacs@gnu.org; Mon, 15 Jul 2013 06:46:53 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:60473) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UygIs-0000gA-8R for help-gnu-emacs@gnu.org; Mon, 15 Jul 2013 06:46:50 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UygIq-00039S-62 for help-gnu-emacs@gnu.org; Mon, 15 Jul 2013 12:46:48 +0200 Original-Received: from tsdh.uni-koblenz.de ([141.26.67.142]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 15 Jul 2013 12:46:48 +0200 Original-Received: from tsdh by tsdh.uni-koblenz.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 15 Jul 2013 12:46:48 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 46 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: tsdh.uni-koblenz.de User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:2rUl4QhkX4nQ4JcwU6NJFo4WZm4= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:92133 Archived-At: John Leach writes: >>> I'm starting a process using start-process-shell-command, but the >>> command I'm running doesn't exit when it receives a SIGHUP (it >>> reloads it's configs or something) so I end up with orphaned >>> processes hanging around when I close the buffer or exit emacs. >> >> I guess you could add a function to `kill-buffer-hook' that calls >> `delete-process' on the process. > > thanks Tassilo. I'm trying to do this but failing. > > So I think I need a kill-buffer-hook that can get the process of the > current buffer, check if it looks like the process I know needs a > SIGTERM, and then send it one. > > I'm wondering if I can set some kind of attribute on the buffer when I > create the process, so I can easily recognise it at kill time? You could use a buffer-local variable. E.g. --8<---------------cut here---------------start------------->8--- (defvar nanoc-process nil) (make-variable-buffer-local 'nanoc-process) (defun nanoc-kill-process () (when nanoc-process (delete-process nanoc-process))) (defun nanoc-server () "Runs a nanoc web server" (interactive) (let ((default-directory (repository-root)) (process-connection-type t)) (setq nanoc-process (start-process-shell-command "nanoc-server" "nanoc-server" "bundle exec nanoc view -p 3005 -C")) (add-hook 'kill-buffer-hook #'nanoc-kill-process nil t))) --8<---------------cut here---------------end--------------->8--- Then every buffer may have its own nanoc-server process, and when killing the buffer only that buffer's process is deleted. Bye, Tassilo