diff options
| author | Richard M. Stallman | 2002-04-02 21:20:16 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2002-04-02 21:20:16 +0000 |
| commit | 5517ea8a30af128849bfb151cb583688d8da5c1d (patch) | |
| tree | 7662fd92a6d60882c7e77b5bfeed5e28f1ffe9c7 | |
| parent | b1f236d8571ab2ad969c7ea6c08bddda8b8f8bf9 (diff) | |
| download | emacs-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.texi | 151 |
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 |
| 484 | subprocess, and removes it from the list of active processes. It sends | 485 | subprocess. Processes are deleted automatically after they terminate, |
| 485 | a signal to the subprocess to make the subprocess terminate, but this is | 486 | but not necessarily right away. You can delete a process explicitly |
| 486 | not guaranteed to happen immediately. The process object itself | 487 | at any time. If you delete a terminated process explicitly before it |
| 487 | continues to exist as long as other Lisp objects point to it. The | 488 | is deleted automatically, no harm results. Deletion of a running |
| 488 | process mark continues to point to the same place as before (usually | 489 | process sends a signal to terminate it and calls the process sentinel |
| 489 | into a buffer where output from the process was being inserted). | 490 | if 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 |
| 492 | deleted automatically after they terminate, but not necessarily right | 493 | deleted process, but the process object itself continues to exist as |
| 493 | away. If you delete a terminated process explicitly before it is | 494 | long as other Lisp objects point to it. All the Lisp primitives that |
| 494 | deleted automatically, no harm results. | 495 | work on process objects accept deleted processes, but those that do |
| 496 | I/O or send signals will report an error. The process mark continues | ||
| 497 | to point to the same place as before, usually into a buffer where | ||
| 498 | output from the process was being inserted. | ||
| 495 | 499 | ||
| 496 | @defopt delete-exited-processes | 500 | @defopt delete-exited-processes |
| 497 | This variable controls automatic deletion of processes that have | 501 | This 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 |
| 505 | This function deletes the process associated with @var{name}, killing it | 509 | This function deletes the process associated with @var{name}, killing |
| 506 | with a @code{SIGHUP} signal. The argument @var{name} may be a process, | 510 | it with a @code{SIGKILL} signal. The argument @var{name} may be a |
| 507 | the name of a process, a buffer, or the name of a buffer. | 511 | process, the name of a process, a buffer, or the name of a buffer. |
| 512 | Calling @code{delete-process} on a running process terminates it, | ||
| 513 | updates the process status, and runs the sentinel (if any) immediately. | ||
| 514 | If the process has already terminated, calling @code{delete-process} | ||
| 515 | has no effect on its status, or on the running of its sentinel (which | ||
| 516 | will 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 | ||
| 518 | This function specifies whether Emacs should query the user if | ||
| 519 | @var{process} is still running when Emacs is exited. If @var{do-query} | ||
| 520 | is @code{nil}, the process will be deleted silently. | ||
| 521 | Otherwise, Emacs will query about killing it. | ||
| 522 | |||
| 523 | The value is @code{t} if the process was formerly set up to require | ||
| 524 | query, @code{nil} otherwise. A newly-created process always requires | ||
| 525 | query. | ||
| 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 | |||
| 864 | to send; it should be an integer. | 855 | to 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 | ||
| 862 | the @code{SIGHUP} signal. Because some subprocesses are doing | ||
| 863 | valuable work, Emacs normally asks the user to confirm that it is ok | ||
| 864 | to terminate them. Each process has a query flag which, if | ||
| 865 | non-@code{nil}, says that Emacs should ask for confirmation before | ||
| 866 | exiting and thus killing that process. The default for the query flag | ||
| 867 | is @code{t}, meaning @emph{do} query. | ||
| 868 | |||
| 869 | @tindex process-query-on-exit-flag | ||
| 870 | @defun process-query-on-exit-flag process | ||
| 871 | This 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 | ||
| 876 | This function sets the query flag of @var{process} to @var{flag}. It | ||
| 877 | returns @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 | ||
| 889 | This function clears the query flag of @var{process}, so that | ||
| 890 | Emacs will not query the user on account of that process. | ||
| 891 | |||
| 892 | Actually, the function does more than that: it returns the old value of | ||
| 893 | the process's query flag, and sets the query flag to @var{do-query}. | ||
| 894 | Please don't use this function to do those things any more---please | ||
| 895 | use 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. | ||
| 897 | The only way you should use @code{process-kill-without-query} nowadays | ||
| 898 | is 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 |
| 977 | This function returns the process associated with @var{buffer-or-name}. | 1018 | This function returns a nondeleted process associated with the buffer |
| 978 | If there are several processes associated with it, then one is chosen. | 1019 | specified by @var{buffer-or-name}. If there are several processes |
| 979 | (Currently, the one chosen is the one most recently created.) It is | 1020 | associated with it, this function chooses one (currently, the one most |
| 980 | usually a bad idea to have more than one process associated with the | 1021 | recently created, but don't count on that). Deletion of a process |
| 981 | same buffer. | 1022 | (see @code{delete-process}) makes it ineligible for this function to |
| 1023 | return. | ||
| 1024 | |||
| 1025 | It is usually a bad idea to have more than one process associated with | ||
| 1026 | the 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 |
| 1198 | associated process changes status for any reason, including signals | 1243 | associated 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 |
| 1200 | terminate, stop, or continue the process. The process sentinel is also | 1245 | terminate, stop, or continue the process. The process sentinel is |
| 1201 | called if the process exits. The sentinel receives two arguments: the | 1246 | also called if the process exits. The sentinel receives two |
| 1202 | process for which the event occurred, and a string describing the type | 1247 | arguments: the process for which the event occurred, and a string |
| 1203 | of event. | 1248 | describing 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 |
| 1222 | or for time to elapse, or for process output). This avoids the timing | 1267 | input, or for time to elapse, or for process output). This avoids the |
| 1223 | errors that could result from running them at random places in the | 1268 | timing errors that could result from running them at random places in |
| 1224 | middle of other Lisp programs. A program can wait, so that sentinels | 1269 | the middle of other Lisp programs. A program can wait, so that |
| 1225 | will run, by calling @code{sit-for} or @code{sleep-for} | 1270 | sentinels 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 |
| 1227 | Output}). Emacs also allows sentinels to run when the command loop is | 1272 | Output}). Emacs also allows sentinels to run when the command loop is |
| 1228 | reading input. | 1273 | reading input. @code{delete-process} calls the sentinel when it |
| 1274 | terminates a running process. | ||
| 1275 | |||
| 1276 | Emacs does not keep a queue of multiple reasons to call the sentinel | ||
| 1277 | of one process; it records just the current status and the fact that | ||
| 1278 | there has been a change. Therefore two changes in status, coming in | ||
| 1279 | quick succession, can call the sentinel just once. However, process | ||
| 1280 | termination will always run the sentinel exactly once. This is | ||
| 1281 | because 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 |
| 1231 | effect of typing @kbd{C-g} at command level or to quit a user command | 1284 | effect 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 | |||
| 1255 | The default behavior when there is no sentinel is to insert a message in | 1308 | The default behavior when there is no sentinel is to insert a message in |
| 1256 | the process's buffer when the process status changes. | 1309 | the process's buffer when the process status changes. |
| 1257 | 1310 | ||
| 1311 | Changes in process sentinel take effect immediately---if the sentinel | ||
| 1312 | is slated to be run but has not been called yet, and you specify a new | ||
| 1313 | sentinel, 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) |