I am unable to make stop-process work. I expect that it behaves as C-z in a terminal so that I can later continue it with continue-process.

Minimal not working example:

(setq ptest (start-process "test" "*yes*" "yes"))

and then

(stop-process ptest)

returns #<process test> but does nothing (i.e. the process is still writing y into the output buffer *yes*). Especially, running (process-status ptest) says run instead of stop.

What I'm missing ?

Note: GNU Emacs 28.0.50 of 2021-01-20

  • I don't know the difference, but simple.el uses delete-process when a user manages processes from the *Process List* buffer; e.g., when calling process-menu-delete-process.
    – lawlist
    Jun 3 '21 at 22:19
  • 1
    @lawlist Stopped processes can be restarted. They are just suspended. Deleted processes cannot be restarted.
    – Tobias
    Jun 3 '21 at 22:23
  • There is the following phrase in the doc string of interrupt-process: If the process is a shell, this means interrupt current subjob rather than the shell. Might it be that this is the reason you see no effect?
    – Tobias
    Jun 3 '21 at 22:26

On my system, yes doesn't react to SIGTSTP, which is the signal sent by stop-process (rather than SIGSTOP as one might assume).

When you run yes in your terminal and shell, C-z is going to additionally prevent the process from having a terminal to write to -- so if the process is still running and generating output, the kernel will stop it at that point (via SIGTTOU as I understand it). My guess is that that's the difference between the two scenarios.

You can use (signal-process ptest 'STOP) to send SIGSTOP.

 -- Function: stop-process &optional process current-group
     This function stops the specified PROCESS.  If it is a real
     subprocess running a program, it sends the signal ‘SIGTSTP’ to that
     subprocess.  If PROCESS represents a network, serial, or pipe
     connection, this function inhibits handling of the incoming data
     from the connection; for a network server, this means not accepting
     new connections.  Use ‘continue-process’ to resume normal

     Outside of Emacs, on systems with job control, the stop character
     (usually ‘C-z’) normally sends the ‘SIGTSTP’ signal to a
     subprocess.  When CURRENT-GROUP is non-‘nil’, you can think of this
     function as typing ‘C-z’ on the terminal Emacs uses to communicate
     with the subprocess.
  • Thanks! In Ubuntu, C-z does put yes in background, so I expected the same from stop-process. The real-world command I want to stop is mpv, but it doesn't work as expect either. Do you have any command in your system which reacts to stop-process ? I'm surprised that stop-process is not a synonym of (signal-process ptest 'STOP). Jun 4 '21 at 1:56
  • top is an example on my system.
    – phils
    Jun 4 '21 at 2:17
  • Note that "in the background" is about job-control in a shell, and not really relevant to Emacs where everything has its own buffer. I'll speculate that many programs simply assume that job control will be in effect and therefore that they don't need to handle SIGTSTP if the desired result will happen anyway by side-effect.
    – phils
    Jun 4 '21 at 2:28
  • Apparently, SIGTSTP can be ignored, but SIGSTOP cannot. I can't try top with start-process because it says that the env variable TERM is not set properly. Anyway, thanks for the edit, didn't know the nuance between SIGSTOP and SIGTSTP. Jun 4 '21 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.