Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The background for this question: I currently have to do a lot of my work in terminal over ssh, and I use screen quite a bit. Because I found the ctrl-a key binding for screen commands so annoying since I'm accustomed to using ctrl-a to go to the beginning of a line, I changed it to ctrl-z. The only problem with this is that when I'm in Matlab, think I am in Screen but am not, pressing ctrl-z will instantly kill my Matlab session, because ctrl-z is the key binding for suspending processes in *nix.

So the question is: can I remove the key binding for ctrl-z in my shell so that it does no longer suspend a process?

My shell is on OSX.

share|improve this question

migrated from Sep 18 '12 at 19:06

This question came from our site for professional and enthusiast programmers.

Does Ctrl-Z really kill Matlab? The way suspension works is that you get back your shell prompt (at least on the command line). If you're done suspending, you can continue the suspended program with fg (place it in the foreground again). – Jens Sep 18 '12 at 12:52
Thanks, Jens! You are absolutely right. I thought it was killed since I didn't see Matlab in top, but fg brings it back. That solves my problem :) – Nagel Sep 19 '12 at 13:59
up vote 9 down vote accepted

The ^Z binding is not configured in the shell, but in your TTY, the pseudo-device that lets you talk to the physical terminal or, as is typical nowadays, to a terminal emulator program. The TTY carries settings that tell the kernel how to react to keyboard input reported by the device or emulator.

Settings are changed using the stty command:

stty susp "^P"

stty accepts a setting name and its value; in this case the setting name is susp for key that suspends the process, and the value is a key combination, such as ^P. Type stty -a or refer to man stty for a list of available settings.

share|improve this answer

You can wrap your matlab in a script named like this:

trap "" TSTP

That will ignore the TSTP signal usually sent by Ctrl-Z.

share|improve this answer
Thanks! That is a nice workaround. – Nagel Sep 19 '12 at 14:02

Another possibility is to choose a different escape character for screen.

I use the null character. I have the following in my $HOME/.screenrc:

escape ^@^@

The null character can (usually) be entered as Ctrl-Space, which is very easy to type. And of course if I need to send an actual null character to a program (for example, it's bound to set-mark-command in Emacs), I just type Ctrl-Space twice.

(This sometimes causes problems when I'm using a device or terminal emulator that can't send the null character, but that's rare.)

Another possibility is Ctrl-]:

escape ^]^]

which is also easy to type on a US keyboard. (I actually use that in a screen session that runs nested inside my primary screen session, but that's probably more than you want to know.) The only conflict I typically run into with that is that it's the default escape character for the telnet command.

share|improve this answer
Thanks for your reply. I use ctrl-space for something else, though, and ] is not so easily accessible on my Scandinavian keyboard. – Nagel Sep 19 '12 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .