12

Assume you work on a remote server from a local emacs shell (started with M-x shell). If you execute a process which takes too long (for example an ls in a directory with a huge amount of files), you would like to stop that process (in the terminal one would use control-c). I tried C-c C-c but that kills the whole shell... How can I only kill the running process on the remote server and not the whole shell?

Update

Step-by-step:

1) M-x shell (execute on local machine)
2) ssh mylogin@myremotemachine.foo.bar (execute on local machine)
3) sleep 60 (execute on remote machine)
4) C-c C-c (execute in the current shell)

=> instead of still being on the remote host and just the sleep command being killed, the whole remote connection is closed and you are on your local machine again.

jww
  • 97,681
  • 90
  • 411
  • 885
Marius Hofert
  • 6,546
  • 10
  • 48
  • 102
  • I can't reproduce the problem you describe. How about a step-by-step description of how you experience it? – Sean Jan 20 '12 at 20:47
  • thanks, Sean. I updated the question including a step-by-step description – Marius Hofert Jan 20 '12 at 21:23
  • I have the exact same problem, using zsh and emacs 21.4.1 so a fairly old one... – sandos Feb 01 '12 at 07:13
  • FWIW, I can't reproduce this in Emacs 24.3, so you can possibly go back to using `C-c C-c` now. – phils Jan 31 '14 at 03:58
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. Also see [Where do I post questions about Dev Ops?](http://meta.stackexchange.com/q/134306). – jww Jul 09 '15 at 11:47

2 Answers2

22

When I follow the steps you listed, I find myself back at the remote shell prompt. I'm using Emacs 23.1.1.

I find that typing C-q C-c RET also interrupts the remote process, again leaving me at the remote shell prompt. You might try that as an alternate approach.

Sean
  • 29,130
  • 4
  • 80
  • 105
  • 1
    Hi Sean, thanks for helping. Indeed, `C-q C-c RET` works. I still wonder why `C-c C-c` is not working. I'm using: GNU Emacs 24.0.92.1 (x86_64-apple-darwin, NS apple-appkit-1038.36) of 2012-01-15 on bob.porkrind.org [on Mac OS X 10.7.2]. – Marius Hofert Jan 20 '12 at 22:26
  • Thanks @Sean, you should include [this link](https://www.cs.utah.edu/dept/old/texinfo/emacs18/emacs_8.html) in your answer as it explains that `C-q` will insert the next character typed into the buffer. – Mike H-R Jul 26 '14 at 20:38
  • 1
    @MikeH-R That link no longer exists. So from the [archive](https://web.archive.org/web/20130215033411/https://www.cs.utah.edu/dept/old/texinfo/emacs18/emacs_8.html) – Terry Aug 23 '19 at 11:25
-1

It is unclear to me if you want to kill the command from within emacs, but you could alternately open another connection or window (if you are using screen or tmux) and perform the standard

ps aux | grep hungprocess

and then

kill hungprocess_pid

For some reason I kept thinking that such a method wouldn't work and that I'd end up taking down emacs as well. I have used such a method multiple times when I haven't set up my gpg pinentry agent when opening a gpg encrypted file in emacs. Emacs/gpg will try to spawn a GUI and therefore hangs emacs, waiting for input in the GUI when I am remotely ssh'ed in.

N Klosterman
  • 1,231
  • 14
  • 23