aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2002-04-02 21:20:16 +0000
committerRichard M. Stallman2002-04-02 21:20:16 +0000
commit5517ea8a30af128849bfb151cb583688d8da5c1d (patch)
tree7662fd92a6d60882c7e77b5bfeed5e28f1ffe9c7
parentb1f236d8571ab2ad969c7ea6c08bddda8b8f8bf9 (diff)
downloademacs-5517ea8a30af128849bfb151cb583688d8da5c1d.tar.gz
emacs-5517ea8a30af128849bfb151cb583688d8da5c1d.zip
New node Query Before Exit broken out of Deleting Processes.
Explain more details of process deletion and sentinels. Document process-query-on-exit-flag and set-process-query-on-exit-flag.
-rw-r--r--lispref/processes.texi151
1 files changed, 104 insertions, 47 deletions
diff --git a/lispref/processes.texi b/lispref/processes.texi
index 7cf9607efc1..81023719429 100644
--- a/lispref/processes.texi
+++ b/lispref/processes.texi
@@ -43,6 +43,7 @@ This function returns @code{t} if @var{object} is a process,
43* Input to Processes:: Sending input to an asynchronous subprocess. 43* Input to Processes:: Sending input to an asynchronous subprocess.
44* Signals to Processes:: Stopping, continuing or interrupting 44* Signals to Processes:: Stopping, continuing or interrupting
45 an asynchronous subprocess. 45 an asynchronous subprocess.
46* Query Before Exit:: Whether to query if exiting will kill a process.
46* Output from Processes:: Collecting output from an asynchronous subprocess. 47* Output from Processes:: Collecting output from an asynchronous subprocess.
47* Sentinels:: Sentinels run when process run-status changes. 48* Sentinels:: Sentinels run when process run-status changes.
48* Transaction Queues:: Transaction-based communication with subprocesses. 49* Transaction Queues:: Transaction-based communication with subprocesses.
@@ -481,17 +482,20 @@ Information}).
481@cindex deleting processes 482@cindex deleting processes
482 483
483 @dfn{Deleting a process} disconnects Emacs immediately from the 484 @dfn{Deleting a process} disconnects Emacs immediately from the
484subprocess, and removes it from the list of active processes. It sends 485subprocess. Processes are deleted automatically after they terminate,
485a signal to the subprocess to make the subprocess terminate, but this is 486but not necessarily right away. You can delete a process explicitly
486not guaranteed to happen immediately. The process object itself 487at any time. If you delete a terminated process explicitly before it
487continues to exist as long as other Lisp objects point to it. The 488is deleted automatically, no harm results. Deletion of a running
488process mark continues to point to the same place as before (usually 489process sends a signal to terminate it and calls the process sentinel
489into a buffer where output from the process was being inserted). 490if it has one.
490 491
491 You can delete a process explicitly at any time. Processes are 492 @code{get-buffer-process} and @code{process-list} do not remember a
492deleted automatically after they terminate, but not necessarily right 493deleted process, but the process object itself continues to exist as
493away. If you delete a terminated process explicitly before it is 494long as other Lisp objects point to it. All the Lisp primitives that
494deleted automatically, no harm results. 495work on process objects accept deleted processes, but those that do
496I/O or send signals will report an error. The process mark continues
497to point to the same place as before, usually into a buffer where
498output from the process was being inserted.
495 499
496@defopt delete-exited-processes 500@defopt delete-exited-processes
497This variable controls automatic deletion of processes that have 501This variable controls automatic deletion of processes that have
@@ -502,9 +506,14 @@ they exit.
502@end defopt 506@end defopt
503 507
504@defun delete-process name 508@defun delete-process name
505This function deletes the process associated with @var{name}, killing it 509This function deletes the process associated with @var{name}, killing
506with a @code{SIGHUP} signal. The argument @var{name} may be a process, 510it with a @code{SIGKILL} signal. The argument @var{name} may be a
507the name of a process, a buffer, or the name of a buffer. 511process, the name of a process, a buffer, or the name of a buffer.
512Calling @code{delete-process} on a running process terminates it,
513updates the process status, and runs the sentinel (if any) immediately.
514If the process has already terminated, calling @code{delete-process}
515has no effect on its status, or on the running of its sentinel (which
516will happen sooner or later).
508 517
509@smallexample 518@smallexample
510@group 519@group
@@ -514,24 +523,6 @@ the name of a process, a buffer, or the name of a buffer.
514@end smallexample 523@end smallexample
515@end defun 524@end defun
516 525
517@defun process-kill-without-query process &optional do-query
518This function specifies whether Emacs should query the user if
519@var{process} is still running when Emacs is exited. If @var{do-query}
520is @code{nil}, the process will be deleted silently.
521Otherwise, Emacs will query about killing it.
522
523The value is @code{t} if the process was formerly set up to require
524query, @code{nil} otherwise. A newly-created process always requires
525query.
526
527@smallexample
528@group
529(process-kill-without-query (get-process "shell"))
530 @result{} t
531@end group
532@end smallexample
533@end defun
534
535@node Process Information 526@node Process Information
536@section Process Information 527@section Process Information
537 528
@@ -864,6 +855,56 @@ a child of Emacs. The argument @var{signal} specifies which signal
864to send; it should be an integer. 855to send; it should be an integer.
865@end defun 856@end defun
866 857
858@node Query Before Exit
859@section Querying Before Exit
860
861 When Emacs exits, it terminates all its subprocesses by sending them
862the @code{SIGHUP} signal. Because some subprocesses are doing
863valuable work, Emacs normally asks the user to confirm that it is ok
864to terminate them. Each process has a query flag which, if
865non-@code{nil}, says that Emacs should ask for confirmation before
866exiting and thus killing that process. The default for the query flag
867is @code{t}, meaning @emph{do} query.
868
869@tindex process-query-on-exit-flag
870@defun process-query-on-exit-flag process
871This returns the query flag of @var{process}.
872@end defun
873
874@tindex set-process-query-on-exit-flag
875@defun set-process-query-on-exit-flag process flag
876This function sets the query flag of @var{process} to @var{flag}. It
877returns @var{flag}.
878
879@smallexample
880@group
881;; @r{Don't query about the shell process}
882(set-process-query-on-exit-flag (get-process "shell") nil)
883 @result{} t
884@end group
885@end smallexample
886@end defun
887
888@defun process-kill-without-query process &optional do-query
889This function clears the query flag of @var{process}, so that
890Emacs will not query the user on account of that process.
891
892Actually, the function does more than that: it returns the old value of
893the process's query flag, and sets the query flag to @var{do-query}.
894Please don't use this function to do those things any more---please
895use the newer, cleaner functions @code{process-query-on-exit-flag} and
896@code{set-process-query-on-exit-flag} in all but the simplest cases.
897The only way you should use @code{process-kill-without-query} nowadays
898is like this:
899
900@smallexample
901@group
902;; @r{Don't query about the shell process}
903(process-kill-without-query (get-process "shell"))
904@end group
905@end smallexample
906@end defun
907
867@node Output from Processes 908@node Output from Processes
868@section Receiving Output from Processes 909@section Receiving Output from Processes
869@cindex process output 910@cindex process output
@@ -974,11 +1015,15 @@ associated with no buffer.
974@end defun 1015@end defun
975 1016
976@defun get-buffer-process buffer-or-name 1017@defun get-buffer-process buffer-or-name
977This function returns the process associated with @var{buffer-or-name}. 1018This function returns a nondeleted process associated with the buffer
978If there are several processes associated with it, then one is chosen. 1019specified by @var{buffer-or-name}. If there are several processes
979(Currently, the one chosen is the one most recently created.) It is 1020associated with it, this function chooses one (currently, the one most
980usually a bad idea to have more than one process associated with the 1021recently created, but don't count on that). Deletion of a process
981same buffer. 1022(see @code{delete-process}) makes it ineligible for this function to
1023return.
1024
1025It is usually a bad idea to have more than one process associated with
1026the same buffer.
982 1027
983@smallexample 1028@smallexample
984@group 1029@group
@@ -1197,10 +1242,10 @@ arrived.
1197 A @dfn{process sentinel} is a function that is called whenever the 1242 A @dfn{process sentinel} is a function that is called whenever the
1198associated process changes status for any reason, including signals 1243associated process changes status for any reason, including signals
1199(whether sent by Emacs or caused by the process's own actions) that 1244(whether sent by Emacs or caused by the process's own actions) that
1200terminate, stop, or continue the process. The process sentinel is also 1245terminate, stop, or continue the process. The process sentinel is
1201called if the process exits. The sentinel receives two arguments: the 1246also called if the process exits. The sentinel receives two
1202process for which the event occurred, and a string describing the type 1247arguments: the process for which the event occurred, and a string
1203of event. 1248describing the type of event.
1204 1249
1205 The string describing the event looks like one of the following: 1250 The string describing the event looks like one of the following:
1206 1251
@@ -1218,14 +1263,22 @@ of event.
1218@code{"@var{name-of-signal} (core dumped)\n"}. 1263@code{"@var{name-of-signal} (core dumped)\n"}.
1219@end itemize 1264@end itemize
1220 1265
1221 A sentinel runs only while Emacs is waiting (e.g., for terminal input, 1266 A sentinel runs only while Emacs is waiting (e.g., for terminal
1222or for time to elapse, or for process output). This avoids the timing 1267input, or for time to elapse, or for process output). This avoids the
1223errors that could result from running them at random places in the 1268timing errors that could result from running them at random places in
1224middle of other Lisp programs. A program can wait, so that sentinels 1269the middle of other Lisp programs. A program can wait, so that
1225will run, by calling @code{sit-for} or @code{sleep-for} 1270sentinels will run, by calling @code{sit-for} or @code{sleep-for}
1226(@pxref{Waiting}), or @code{accept-process-output} (@pxref{Accepting 1271(@pxref{Waiting}), or @code{accept-process-output} (@pxref{Accepting
1227Output}). Emacs also allows sentinels to run when the command loop is 1272Output}). Emacs also allows sentinels to run when the command loop is
1228reading input. 1273reading input. @code{delete-process} calls the sentinel when it
1274terminates a running process.
1275
1276 Emacs does not keep a queue of multiple reasons to call the sentinel
1277of one process; it records just the current status and the fact that
1278there has been a change. Therefore two changes in status, coming in
1279quick succession, can call the sentinel just once. However, process
1280termination will always run the sentinel exactly once. This is
1281because the process status can't change again after termination.
1229 1282
1230 Quitting is normally inhibited within a sentinel---otherwise, the 1283 Quitting is normally inhibited within a sentinel---otherwise, the
1231effect of typing @kbd{C-g} at command level or to quit a user command 1284effect of typing @kbd{C-g} at command level or to quit a user command
@@ -1255,6 +1308,10 @@ This function associates @var{sentinel} with @var{process}. If
1255The default behavior when there is no sentinel is to insert a message in 1308The default behavior when there is no sentinel is to insert a message in
1256the process's buffer when the process status changes. 1309the process's buffer when the process status changes.
1257 1310
1311Changes in process sentinel take effect immediately---if the sentinel
1312is slated to be run but has not been called yet, and you specify a new
1313sentinel, the eventual call to the sentinel will use the new one.
1314
1258@smallexample 1315@smallexample
1259@group 1316@group
1260(defun msg-me (process event) 1317(defun msg-me (process event)