1

I seem to have a peculiar issue with MacOS Terminal (or iTerm) from time to time and I cannot pinpoint the cause.

Whenever I need to kill a program in Terminal, Control + C doesn't work. Terminal simply outputs ^Z for every Control + C.

^Z^Z^Z^Z^Z^Z^Z
^Z^Z
^Z^Z^Z
^Z^Z^Z

It's not limited to Control + C:

  • I get ^X for Control + X
  • ^C for Control + C
  • And so on.

It happens from time to time. Sometimes it's working, then it's not, then it's back again working.

What I've tried:

  • Removed almost all Keyboard shortcuts that start with Control. I've left only those that start with Control + F.

  • Keyboard Viewer does the same (ie. ^Z).

  • Modifier Keys are the default ones.

  • Tried to switch between apps to determine if an app may "hijack" the Control key, but I cannot pinpoint if that's the cause and if so, what's that app (ie. Chrome, TextMate, Notes.app).

  • Output of stty -a:

lflags: icanon isig iexten echo echoe echok echoke -echonl echoctl
    -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
    -extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8
    -ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
    -dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
    eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
    min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
    stop = ^S; susp = ^Z; time = 0; werase = ^W;```
Max
  • 71
  • 4
  • Terminal is the only application where you've noticed a strange keyboard behavior? Did you install any app at all that helps customize keyboard shortcuts, such as Maestro, or some other older app like Rocket Ship or QuickSilver? –  Mar 26 '20 at 15:58
  • I did install Spectacle app that can organize windows, I've uninstalled it and I get the same behavior after a restart. – Max Mar 29 '20 at 19:59
  • Maybe the kext and .plist have been left behind during your uninstall and someone still interfere with your keyboard. You should try to reinstall Spectacle, then uninstall it completely using AppRemover (here: https://www.macupdate.com/app/mac/42895/mac-malware-remover). It'll get rid of the leftovers for you. Reboot your Mac when done and tell us how it goes. –  Mar 29 '20 at 21:14
  • I've uninstalled Spectacle and I'll have a look at that Remover but it's seems to be quite old for Catalina. – Max Apr 01 '20 at 09:07
  • I checked, and though AppRemover was developped for older versions of OS X (back then), it is still compatible with macOS. The good thing with AppRemover is that it does a thorough job at uninstalling apps. It leaves no leftovers, while drag-dropping your app to the Trash DOES leave files behind. –  Apr 01 '20 at 09:17
  • Thanks. I was able to pinpoint the issue further more. It happens only when I'm SSH-ing into a server and it happens only if I hit `Ctrl`+`Z` first. If I use `Ctrl`+`C` first, it works; if I use `Ctrl`+`Z` and then `Ctrl+`C`, it no longer works. I'll just leave it like that. – Max Apr 02 '20 at 13:31
  • Maybe the keyboard layout on the distant machine is different from yours. Could be it's on a machine wheyre the original keyboard layout was or is AZERTY (as is mine) and yours is QWERTY. In that case, the first command you enter could still be interpreted based on the local (distant) keyboard layout, and the following commands on your own. To be honest, I'm grasping at straws here. I've seen strange keyboard behavior in Unix, but never this... :-) –  Apr 02 '20 at 13:37

3 Answers3

1

What is your output for stty -a from terminal?

You're looking for intr = ^C;

This may be helpful: Ctrl-C and Ctrl-Z not working in terminal

  • `intr = ^C;` is show in `stty -a`. I've tested it when `Ctrl` + `C` worked and when it didn't, it had `intr = ^C;`. – Max Mar 29 '20 at 20:00
  • I've just run across this, perhaps it will help: https://apple.stackexchange.com/questions/104074/find-which-process-receives-a-given-keyboard-command. – Wyatt McGehee Mar 30 '20 at 19:05
  • I'm looking into that, I've got some errors from `dtrace` that I need to disable first to begin the hunt. I've also discovered that the `Control` + `C` doesn't work only when I'm SSH-into into a server, but locally works 100% of the times I've tested. – Max Apr 01 '20 at 09:08
  • Thanks. I was able to pinpoint the issue further more. It happens only when I'm SSH-ing into a server and it happens only if I hit `Ctrl`+`Z` first. If I use `Ctrl`+`C` first, it works; if I use `Ctrl`+`Z` and then `Ctrl+`C`, it no longer works. I'll just leave it like that. – Max Apr 02 '20 at 13:31
1

I was able to pinpoint the issue further more.

It happens only when I'm SSH-ing into a server and it happens only if I hit Ctrl+Z first to interrupt the program.

If I use Ctrl+C first, it works; if I use Ctrl+Z and then Ctrl+C, it no longer works (the entire program is no longer getting any input).

I guess I'll just leave it like that.

Other findings that might help others:

  • ShortcutDetective app [1] helps only if the issue is locally (ie. app that "steals" your shortcut).

  • There's was a bug reported related to tail or cat & Bash version v3.2.48(1)-release [2].

  • Since Catalina ships with zsh, I've tried to use the latest version of zsh from homebrew rather than the one installed with Catalina.

    % zsh --version
    zsh 5.7.1 (x86_64-apple-darwin19.0)
    
    % brew info zsh
    zsh: stable 5.8 (bottled), HEAD
    
    % brew install zsh
    [...]
    ==> Pouring zsh-5.8.catalina.bottle.tar.gz
      /usr/local/Cellar/zsh/5.8: 1,531 files, 13.7MB
    
  • Another thread [3] reported that the issue may be from rvm so I uninstalled it completely as I wasn't using it.

    % rvm version
    rvm 1.25.15 (stable)
    

[1] https://apple.stackexchange.com/questions/104074/find-which-process-receives-a-given-keyboard-command

[2] Mac OS Terminal - keyboard echo breaks after ctrl-c with some applications

[3] ^C not working in zsh on Mac OSX

Max
  • 71
  • 4
  • Logically, all of that makes sense. `Ctrl`+`Z` suspends the current foreground process, where, by definition, it does not receive input, including a `Ctrl`+`C`. A suspended foreground process can be resumed in the background with the `bg` command or in the foreground with `fg` command. – Wyatt McGehee Apr 02 '20 at 21:57
0

This is an extremely long standing issue with macOS, incredibly irritating and very easy to reproduce:

  1. Open a new Terminal.app window running zsh.
  2. Open vim with a file, eg “vim /etc/passwd”
  3. Move the cursor by pressing the down arrow (not “j” - the down arrow)
  4. Suspend vim with Ctrl-Z
  5. Type Ctrl-C

It seems to be a combination of zsh (from Apple or from Homebrew, makes no difference) and macOS Terminal.app - other terminal apps seem OK, and I have reproduced this on a new machine so it's nothing to do with third-party applications.

While I haven't found a solution, to make Ctrl-C work again after it has happened, in the terminal run:

trap -

File an issue with Apple, I have. Hopefully if enough complain it will get fixed.

Mike B
  • 101
  • 1