43 |
* Input to Processes:: Sending input to an asynchronous subprocess. |
* Input to Processes:: Sending input to an asynchronous subprocess. |
44 |
* Signals to Processes:: Stopping, continuing or interrupting |
* Signals to Processes:: Stopping, continuing or interrupting |
45 |
an asynchronous subprocess. |
an asynchronous subprocess. |
46 |
|
* Query Before Exit:: Whether to query if exiting will kill a process. |
47 |
* Output from Processes:: Collecting output from an asynchronous subprocess. |
* Output from Processes:: Collecting output from an asynchronous subprocess. |
48 |
* Sentinels:: Sentinels run when process run-status changes. |
* Sentinels:: Sentinels run when process run-status changes. |
49 |
* Transaction Queues:: Transaction-based communication with subprocesses. |
* Transaction Queues:: Transaction-based communication with subprocesses. |
482 |
@cindex deleting processes |
@cindex deleting processes |
483 |
|
|
484 |
@dfn{Deleting a process} disconnects Emacs immediately from the |
@dfn{Deleting a process} disconnects Emacs immediately from the |
485 |
subprocess, and removes it from the list of active processes. It sends |
subprocess. Processes are deleted automatically after they terminate, |
486 |
a signal to the subprocess to make the subprocess terminate, but this is |
but not necessarily right away. You can delete a process explicitly |
487 |
not guaranteed to happen immediately. The process object itself |
at any time. If you delete a terminated process explicitly before it |
488 |
continues to exist as long as other Lisp objects point to it. The |
is deleted automatically, no harm results. Deletion of a running |
489 |
process mark continues to point to the same place as before (usually |
process sends a signal to terminate it and calls the process sentinel |
490 |
into a buffer where output from the process was being inserted). |
if it has one. |
491 |
|
|
492 |
You can delete a process explicitly at any time. Processes are |
@code{get-buffer-process} and @code{process-list} do not remember a |
493 |
deleted automatically after they terminate, but not necessarily right |
deleted process, but the process object itself continues to exist as |
494 |
away. If you delete a terminated process explicitly before it is |
long as other Lisp objects point to it. All the Lisp primitives that |
495 |
deleted automatically, no harm results. |
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. |
499 |
|
|
500 |
@defopt delete-exited-processes |
@defopt delete-exited-processes |
501 |
This variable controls automatic deletion of processes that have |
This variable controls automatic deletion of processes that have |
506 |
@end defopt |
@end defopt |
507 |
|
|
508 |
@defun delete-process name |
@defun delete-process name |
509 |
This function deletes the process associated with @var{name}, killing it |
This function deletes the process associated with @var{name}, killing |
510 |
with a @code{SIGHUP} signal. The argument @var{name} may be a process, |
it with a @code{SIGKILL} signal. The argument @var{name} may be a |
511 |
the name of a process, a buffer, or the name of a buffer. |
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). |
517 |
|
|
518 |
@smallexample |
@smallexample |
519 |
@group |
@group |
523 |
@end smallexample |
@end smallexample |
524 |
@end defun |
@end defun |
525 |
|
|
|
@defun process-kill-without-query process &optional do-query |
|
|
This function specifies whether Emacs should query the user if |
|
|
@var{process} is still running when Emacs is exited. If @var{do-query} |
|
|
is @code{nil}, the process will be deleted silently. |
|
|
Otherwise, Emacs will query about killing it. |
|
|
|
|
|
The value is @code{t} if the process was formerly set up to require |
|
|
query, @code{nil} otherwise. A newly-created process always requires |
|
|
query. |
|
|
|
|
|
@smallexample |
|
|
@group |
|
|
(process-kill-without-query (get-process "shell")) |
|
|
@result{} t |
|
|
@end group |
|
|
@end smallexample |
|
|
@end defun |
|
|
|
|
526 |
@node Process Information |
@node Process Information |
527 |
@section Process Information |
@section Process Information |
528 |
|
|
855 |
to send; it should be an integer. |
to send; it should be an integer. |
856 |
@end defun |
@end defun |
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 |
|
|
908 |
@node Output from Processes |
@node Output from Processes |
909 |
@section Receiving Output from Processes |
@section Receiving Output from Processes |
910 |
@cindex process output |
@cindex process output |
1015 |
@end defun |
@end defun |
1016 |
|
|
1017 |
@defun get-buffer-process buffer-or-name |
@defun get-buffer-process buffer-or-name |
1018 |
This function returns the process associated with @var{buffer-or-name}. |
This function returns a nondeleted process associated with the buffer |
1019 |
If there are several processes associated with it, then one is chosen. |
specified by @var{buffer-or-name}. If there are several processes |
1020 |
(Currently, the one chosen is the one most recently created.) It is |
associated with it, this function chooses one (currently, the one most |
1021 |
usually a bad idea to have more than one process associated with the |
recently created, but don't count on that). Deletion of a process |
1022 |
same buffer. |
(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. |
1027 |
|
|
1028 |
@smallexample |
@smallexample |
1029 |
@group |
@group |
1242 |
A @dfn{process sentinel} is a function that is called whenever the |
A @dfn{process sentinel} is a function that is called whenever the |
1243 |
associated process changes status for any reason, including signals |
associated process changes status for any reason, including signals |
1244 |
(whether sent by Emacs or caused by the process's own actions) that |
(whether sent by Emacs or caused by the process's own actions) that |
1245 |
terminate, stop, or continue the process. The process sentinel is also |
terminate, stop, or continue the process. The process sentinel is |
1246 |
called if the process exits. The sentinel receives two arguments: the |
also called if the process exits. The sentinel receives two |
1247 |
process for which the event occurred, and a string describing the type |
arguments: the process for which the event occurred, and a string |
1248 |
of event. |
describing the type of event. |
1249 |
|
|
1250 |
The string describing the event looks like one of the following: |
The string describing the event looks like one of the following: |
1251 |
|
|
1263 |
@code{"@var{name-of-signal} (core dumped)\n"}. |
@code{"@var{name-of-signal} (core dumped)\n"}. |
1264 |
@end itemize |
@end itemize |
1265 |
|
|
1266 |
A sentinel runs only while Emacs is waiting (e.g., for terminal input, |
A sentinel runs only while Emacs is waiting (e.g., for terminal |
1267 |
or for time to elapse, or for process output). This avoids the timing |
input, or for time to elapse, or for process output). This avoids the |
1268 |
errors that could result from running them at random places in the |
timing errors that could result from running them at random places in |
1269 |
middle of other Lisp programs. A program can wait, so that sentinels |
the middle of other Lisp programs. A program can wait, so that |
1270 |
will run, by calling @code{sit-for} or @code{sleep-for} |
sentinels will run, by calling @code{sit-for} or @code{sleep-for} |
1271 |
(@pxref{Waiting}), or @code{accept-process-output} (@pxref{Accepting |
(@pxref{Waiting}), or @code{accept-process-output} (@pxref{Accepting |
1272 |
Output}). Emacs also allows sentinels to run when the command loop is |
Output}). Emacs also allows sentinels to run when the command loop is |
1273 |
reading input. |
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. |
1282 |
|
|
1283 |
Quitting is normally inhibited within a sentinel---otherwise, the |
Quitting is normally inhibited within a sentinel---otherwise, the |
1284 |
effect of typing @kbd{C-g} at command level or to quit a user command |
effect of typing @kbd{C-g} at command level or to quit a user command |
1308 |
The default behavior when there is no sentinel is to insert a message in |
The default behavior when there is no sentinel is to insert a message in |
1309 |
the process's buffer when the process status changes. |
the process's buffer when the process status changes. |
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 |
|
|
1315 |
@smallexample |
@smallexample |
1316 |
@group |
@group |
1317 |
(defun msg-me (process event) |
(defun msg-me (process event) |