Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 terminal.app on OSX.

share|improve this question

migrated from stackoverflow.com Sep 18 '12 at 19:06

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

7  
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

3 Answers 3

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

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 can wrap your matlab in a script named matlab.sh like this:

#!/bin/sh
trap "" TSTP
/path/to/matlab-executable

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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