How can I interrupt a process with a new key mapping other than Ctrl+C?

PROBLEM DESCRIPTION or QUESTION


I’ve assigned Ctrl+C to copy a string in Xshell so I am no longer able to stop or interrupt a process using this key combination. How can I resolve this?

RESOLUTION


Typically, the Ctrl+C keys are used to interrupt (intr) a process in progress. However, if you are unsure, you can check to see which keys are currently being used by using the ‘stty -a’ command.

$ stty -a
speed 38400 baud; rows 47; columns 236; line = 0;
intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;

In Xshell, If you assign Ctrl+C to copy a string, Xshell will no longer send the key value to the server, and you will not be able to stop a running process. If this is the case, you can stop a process using one of the following methods:

 

Assign a new key value for the intr signal in the terminal

You can assign a new key value for the intr signal. Make sure to assign a key value that is not being used elsewhere.

$ stty intr ^K
$ stty -a
speed 38400 baud; rows 47; columns 236; line = 0;
intr = ^K; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;

^K is a single character representing the ASCII code’s 11th character. This character is expressed by pressing Ctrl+V, Ctrl+K keys successively in the terminal. In some terminals, typing as two separate characters ‘^' and 'K’ may also be recognized.

 

Assign a new key in Xshell

In Xshell, you can set a new key for Ctrl+C key value by using a custom key mapping. Let's use Ctrl+Shift+C as an example.

  1. Go to ‘Tools → Options → Keyboard and Mouse → Edit’ to open the ‘Custom Key mapping’ window.

  2. Click ‘New’ and then type the ‘Ctrl+Shift+C’ key combination.

     

  3. In the ‘Edit’ dialog box, select the ‘Send String’ Action Type, and enter ‘\003’ (which represents the ASCII code value of Ctrl+C) as the String.



  4. After saving these settings, try pressing Ctrl+Shift+C in the terminal to interrupt an ongoing process to confirm that the key mapping was successful.